diff --git a/src/Makefile.am b/src/Makefile.am index 23cff51cba9..eb8c5b8eb79 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -478,6 +478,7 @@ libbitcoin_common_a_SOURCES = \ crypto/verus_hash.h \ crypto/verus_hash.cpp \ hash.cpp \ + hex.c \ importcoin.cpp \ key.cpp \ key_io.cpp \ diff --git a/src/Makefile.ktest.include b/src/Makefile.ktest.include index bfbccc196ad..9bbd99d0ffb 100644 --- a/src/Makefile.ktest.include +++ b/src/Makefile.ktest.include @@ -14,7 +14,8 @@ komodo_test_SOURCES = \ test-komodo/test_sha256_crypto.cpp \ test-komodo/test_script_standard_tests.cpp \ test-komodo/test_addrman.cpp \ - test-komodo/test_netbase_tests.cpp + test-komodo/test_netbase_tests.cpp \ + test-komodo/test_hex.cpp komodo_test_CPPFLAGS = $(komodod_CPPFLAGS) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index ef7b09a37f0..a63e87129a3 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -108,7 +108,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) // // Start // -extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY; +extern bool IS_KOMODO_NOTARY; +extern int32_t USE_EXTERNAL_PUBKEY; extern uint32_t ASSETCHAIN_INIT; extern std::string NOTARY_PUBKEY; int32_t komodo_is_issuer(); diff --git a/src/bits256.h b/src/bits256.h new file mode 100644 index 00000000000..33c54ad558c --- /dev/null +++ b/src/bits256.h @@ -0,0 +1,14 @@ +#pragma once +#include "stdint.h" + +union _bits128 { uint8_t bytes[16]; uint16_t ushorts[8]; uint32_t uints[4]; uint64_t ulongs[2]; uint64_t txid; }; +typedef union _bits128 bits128; + +union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; +typedef union _bits256 bits256; + +union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; }; +typedef union _bits320 bits320; + +union _bits384 { bits256 sig; uint8_t bytes[48]; uint16_t ushorts[24]; uint32_t uints[12]; uint64_t ulongs[6]; uint64_t txid; }; +typedef union _bits384 bits384; \ No newline at end of file diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 6c66b3599fd..ac13bd6d5a4 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -12,7 +12,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - +#include "hex.h" #include "key_io.h" #include "CCinclude.h" #include "CCassets.h" diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 1d28e2cc939..6b5fde79fa7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -85,13 +85,6 @@ Details. #define CCDISABLEALL memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)) #define CCENABLE(x) ASSETCHAINS_CCDISABLES[((uint8_t)x)] = 0 -/* moved to komodo_cJSON.h -#ifndef _BITS256 -#define _BITS256 - union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; - typedef union _bits256 bits256; -#endif -*/ /// \endcond /// identifiers of additional data blobs in token opreturn script: @@ -285,13 +278,6 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo /// @param[out] currentheight current chain height bool NSPV_myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, int32_t &txheight, int32_t ¤theight); -/// decodes char array in hex encoding to byte array -int32_t decode_hex(uint8_t *bytes, int32_t n, char *hex); - -/// checks if char string has hex symbols -/// @returns no zero if string has only hex symbols -int32_t is_hexstr(char *str,int32_t n); - /// CCgettxout returns the amount of an utxo. The function does this without loading the utxo transaction from the chain, by using coin cache /// @param txid transaction id of the utxo /// @param vout utxo transaction vout order number diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 36495314887..f4a4db8444e 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -26,6 +26,7 @@ #include "chain.h" #include "core_io.h" #include "crosschain.h" +#include "hex.h" #define FAUCET2SIZE COIN #define EVAL_FAUCET2 EVAL_FIRSTUSER @@ -612,7 +613,7 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; - decode_hex(buf,len,(char *)rawhex.c_str()); + decode_hex(buf,len,rawhex.c_str()); hash = bits256_doublesha256(0,buf,len); if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { diff --git a/src/cc/crypto777/OS_portable.h b/src/cc/crypto777/OS_portable.h index e0b185cbc72..5dd8f388f9f 100755 --- a/src/cc/crypto777/OS_portable.h +++ b/src/cc/crypto777/OS_portable.h @@ -288,7 +288,6 @@ int64_t iguana_memfree(struct OS_memspace *mem,void *ptr,int32_t size); // generic functions bits256 iguana_merkle(char *symbol,bits256 *tree,int32_t txn_count); bits256 bits256_calctxid(char *symbol,uint8_t *serialized,int32_t len); -int32_t unhex(char c); void touppercase(char *str); uint32_t is_ipaddr(char *str); void iguana_bitmap(char *space,int32_t max,char *name); @@ -298,13 +297,10 @@ uint64_t stringbits(char *str); int32_t is_decimalstr(char *str); void tolowercase(char *str); char *clonestr(char *str); -int32_t is_hexstr(char *str,int32_t n); -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); void reverse_hexstr(char *str); int32_t init_hexbytes_noT(char *hexbytes,uint8_t *message,long len); uint16_t parse_ipaddr(char *ipaddr,char *ip_port); int32_t bitweight(uint64_t x); -uint8_t _decode_hex(char *hex); char *uppercase_str(char *buf,char *str); char *lowercase_str(char *buf,char *str); int32_t strsearch(char *strs[],int32_t num,char *name); diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 82366315c95..38f7a75f739 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -22,6 +22,7 @@ #include #include #include +#include "bits256.h" extern struct games_state globalR; void *gamesiterate(struct games_state *rs); @@ -39,12 +40,6 @@ char whoami[MAXSTR]; #define KOMODO_ASSETCHAIN_MAXLEN 65 char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],IPADDRESS[100]; -#ifndef _BITS256 -#define _BITS256 -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; -#endif - #ifdef _WIN32 #ifdef _MSC_VER int gettimeofday(struct timeval * tp, struct timezone * tzp) @@ -81,112 +76,6 @@ double OS_milliseconds() return(millis); } -int32_t _unhex(char c) -{ - if ( c >= '0' && c <= '9' ) - return(c - '0'); - else if ( c >= 'a' && c <= 'f' ) - return(c - 'a' + 10); - else if ( c >= 'A' && c <= 'F' ) - return(c - 'A' + 10); - return(-1); -} - -int32_t is_hexstr(char *str,int32_t n) -{ - int32_t i; - if ( str == 0 || str[0] == 0 ) - return(0); - for (i=0; str[i]!=0; i++) - { - if ( n > 0 && i >= n ) - break; - if ( _unhex(str[i]) < 0 ) - break; - } - if ( n == 0 ) - return(i); - return(i == n); -} - -int32_t unhex(char c) -{ - int32_t hex; - if ( (hex= _unhex(c)) < 0 ) - { - //printf("unhex: illegal hexchar.(%c)\n",c); - } - return(hex); -} - -unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } - -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) -{ - int32_t adjust,i = 0; - //printf("decode.(%s)\n",hex); - if ( is_hexstr(hex,n) <= 0 ) - { - memset(bytes,0,n); - return(n); - } - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) - { - if ( n > 0 ) - { - bytes[0] = unhex(hex[0]); - printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); - } - bytes++; - hex++; - adjust = 1; - } else adjust = 0; - if ( n > 0 ) - { - for (i=0; i>4) & 0xf); - hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); - //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); - } - hexbytes[len*2] = 0; - //printf("len.%ld\n",len*2+1); - return((int32_t)len*2+1); -} - -char *bits256_str(char hexstr[65],bits256 x) -{ - init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); - return(hexstr); -} - long _stripwhite(char *buf,int accept) { int32_t i,j,c; diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ac1f8840095..1db07722697 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -31,108 +31,6 @@ void myprintf(const char* format, ...) va_end( marker ); } -char hexbyte(int32_t c) -{ - c &= 0xf; - if ( c < 10 ) - return('0'+c); - else if ( c < 16 ) - return('a'+c-10); - else return(0); -} - -int32_t _unhex(char c) -{ - if ( c >= '0' && c <= '9' ) - return(c - '0'); - else if ( c >= 'a' && c <= 'f' ) - return(c - 'a' + 10); - else if ( c >= 'A' && c <= 'F' ) - return(c - 'A' + 10); - return(-1); -} - -int32_t is_hexstr(char *str,int32_t n) -{ - int32_t i; - if ( str == 0 || str[0] == 0 ) - return(0); - for (i=0; str[i]!=0; i++) - { - if ( n > 0 && i >= n ) - break; - if ( _unhex(str[i]) < 0 ) - break; - } - if ( n == 0 ) - return(i); - return(i == n); -} - -int32_t unhex(char c) -{ - int32_t hex; - if ( (hex= _unhex(c)) < 0 ) - { - //myprintf("unhex: illegal hexchar.(%c)\n",c); - } - return(hex); -} - -unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } - -int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex) -{ - int32_t adjust,i = 0; - //myprintf("decode.(%s)\n",hex); - if ( is_hexstr(hex,n) <= 0 ) - { - memset(bytes,0,n); - return(n); - } - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) - { - if ( n > 0 ) - { - bytes[0] = unhex(hex[0]); - myprintf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); - } - bytes++; - hex++; - adjust = 1; - } else adjust = 0; - if ( n > 0 ) - { - for (i=0; i>4) & 0xf); - hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); - //myprintf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); - } - hexbytes[len*2] = 0; - //myprintf("len.%ld\n",len*2+1); - return((int32_t)len*2+1); -} - long _stripwhite(char *buf,int accept) { int32_t i,j,c; diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index f7d9e3feb51..30d8fc5320a 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -35,108 +35,6 @@ bits256 zeroid; -char hexbyte(int32_t c) -{ - c &= 0xf; - if ( c < 10 ) - return('0'+c); - else if ( c < 16 ) - return('a'+c-10); - else return(0); -} - -int32_t _unhex(char c) -{ - if ( c >= '0' && c <= '9' ) - return(c - '0'); - else if ( c >= 'a' && c <= 'f' ) - return(c - 'a' + 10); - else if ( c >= 'A' && c <= 'F' ) - return(c - 'A' + 10); - return(-1); -} - -int32_t is_hexstr(char *str,int32_t n) -{ - int32_t i; - if ( str == 0 || str[0] == 0 ) - return(0); - for (i=0; str[i]!=0; i++) - { - if ( n > 0 && i >= n ) - break; - if ( _unhex(str[i]) < 0 ) - break; - } - if ( n == 0 ) - return(i); - return(i == n); -} - -int32_t unhex(char c) -{ - int32_t hex; - if ( (hex= _unhex(c)) < 0 ) - { - //printf("unhex: illegal hexchar.(%c)\n",c); - } - return(hex); -} - -unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } - -int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex) -{ - int32_t adjust,i = 0; - //printf("decode.(%s)\n",hex); - if ( is_hexstr(hex,n) <= 0 ) - { - memset(bytes,0,n); - return(n); - } - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) - { - if ( n > 0 ) - { - bytes[0] = unhex(hex[0]); - printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); - } - bytes++; - hex++; - adjust = 1; - } else adjust = 0; - if ( n > 0 ) - { - for (i=0; i>4) & 0xf); - hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); - //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); - } - hexbytes[len*2] = 0; - //printf("len.%ld\n",len*2+1); - return((int32_t)len*2+1); -} - long _stripwhite(char *buf,int accept) { int32_t i,j,c; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 48d1049f91f..dc57602cf74 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -12,7 +12,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - +#include "hex.h" #include "CCdice.h" // timeout @@ -936,7 +936,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, if ( (iswin= DiceIsWinner(entropy,entropyvout,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { // will only happen for fundingPubKey - if ( KOMODO_INSYNC != 0 && KOMODO_DEALERNODE != 0 ) + if ( KOMODO_INSYNC != 0 && IS_KOMODO_DEALERNODE != 0 ) DiceQueue(iswin,sbits,fundingtxid,txid,tx,entropyvout); } else @@ -1788,8 +1788,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { - flag = KOMODO_DEALERNODE != 0; - if ( KOMODO_DEALERNODE != 0 && scriptPubKey == fundingPubKey ) + flag = IS_KOMODO_DEALERNODE != 0; + if ( IS_KOMODO_DEALERNODE != 0 && scriptPubKey == fundingPubKey ) { bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,entropyvout,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) @@ -1818,7 +1818,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( didinit == 0 && KOMODO_DEALERNODE == 0 && scriptPubKey == fundingPubKey ) + if ( didinit == 0 && IS_KOMODO_DEALERNODE == 0 && scriptPubKey == fundingPubKey ) { strcpy(_planstr,planstr); dealer0_fundingtxid = fundingtxid; diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 2c0a08451f1..74dfe43d966 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -12,7 +12,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - +#include "hex.h" #include "CCfaucet.h" #include "../txmempool.h" @@ -202,7 +202,7 @@ UniValue FaucetGet(const CPubKey& pk, uint64_t txfee) if ( (len= (int32_t)result[JSON_HEXTX].getValStr().size()) > 0 && len < 65536 ) { len >>= 1; - decode_hex(buf,len,(char *)result[JSON_HEXTX].getValStr().c_str()); + decode_hex(buf,len,result[JSON_HEXTX].getValStr().c_str()); hash = bits256_doublesha256(0,buf,len); if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { diff --git a/src/cc/includes/curve25519.h b/src/cc/includes/curve25519.h index 657fab4d011..46d6b15a5f7 100755 --- a/src/cc/includes/curve25519.h +++ b/src/cc/includes/curve25519.h @@ -19,17 +19,7 @@ #include #include #include - -union _bits128 { uint8_t bytes[16]; uint16_t ushorts[8]; uint32_t uints[4]; uint64_t ulongs[2]; uint64_t txid; }; -typedef union _bits128 bits128; -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; - -union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; }; -typedef union _bits320 bits320; - -union _bits384 { bits256 sig; uint8_t bytes[48]; uint16_t ushorts[24]; uint32_t uints[12]; uint64_t ulongs[6]; uint64_t txid; }; -typedef union _bits384 bits384; +#include "bits256.h" struct sha256_vstate { uint64_t length; uint32_t state[8],curlen; uint8_t buf[64]; }; struct rmd160_vstate { uint64_t length; uint8_t buf[64]; uint32_t curlen, state[5]; }; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 68625c0382b..91c458eaec6 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -12,7 +12,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - +#include "hex.h" #include "CCMarmara.h" /* diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 0c6edb284dc..048ade82adb 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -12,7 +12,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - +#include "hex.h" #include "CCPayments.h" /* diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0fcc2e512c3..f0debddba90 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1961,24 +1961,14 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) for (int i = 0; i<1000000; i++, nonce++) { CMutableTransaction tmpmtx = mtx; - //int32_t len; - //uint8_t txbuf[32768]; rawtx = FinalizeCCTx(0, cp, tmpmtx, mypk, txfee, prices_finalopret(true, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee, nonce)); - //if ((len = (int32_t)rawtx.size()) > 0 && len < sizeof(txbuf) / sizeof(txbuf[0]) * 2) - //{ - // len >>= 1; // sizeof hex divide by 2 - //decode_hex(txbuf, len, (char *)rawtx.c_str()); - //bits256 hash = bits256_doublesha256(0, txbuf, len); - uint256 hash = tmpmtx.GetHash(); - //if ((hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0) - if ((hash.begin()[0] & 0xff) == 0 && (hash.begin()[31] & 0xff) == 0) - { - fprintf(stderr, "found valid txid after %d iterations %u\n", i, (uint32_t)time(NULL)); - return(prices_rawtxresult(result, rawtx, 0)); - } - //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); - //} + uint256 hash = tmpmtx.GetHash(); + if ((hash.begin()[0] & 0xff) == 0 && (hash.begin()[31] & 0xff) == 0) + { + fprintf(stderr, "found valid txid after %d iterations %u\n", i, (uint32_t)time(NULL)); + return(prices_rawtxresult(result, rawtx, 0)); + } } fprintf(stderr, "couldnt generate valid txid %u\n", (uint32_t)time(NULL)); diff --git a/src/cc/rogue/extern.h b/src/cc/rogue/extern.h index c62646b67ee..2c3905daae5 100644 --- a/src/cc/rogue/extern.h +++ b/src/cc/rogue/extern.h @@ -194,7 +194,5 @@ void md_onsignal_exit(void); void md_onsignal_default(void); int md_issymlink(char *sp); -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); - #endif diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 093b73d703d..6774eb32787 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -23,6 +23,8 @@ #include #include +#include "bits256.h" + char USERPASS[8192]; uint16_t ROGUE_PORT; extern char Gametxidstr[67]; @@ -32,12 +34,6 @@ extern char Gametxidstr[67]; #define KOMODO_ASSETCHAIN_MAXLEN 65 char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],IPADDRESS[100]; -#ifndef _BITS256 -#define _BITS256 -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; -#endif - #ifdef _WIN32 #ifdef _MSC_VER int gettimeofday(struct timeval * tp, struct timezone * tzp) @@ -76,112 +72,6 @@ double OS_milliseconds() return(millis); } -int32_t _unhex(char c) -{ - if ( c >= '0' && c <= '9' ) - return(c - '0'); - else if ( c >= 'a' && c <= 'f' ) - return(c - 'a' + 10); - else if ( c >= 'A' && c <= 'F' ) - return(c - 'A' + 10); - return(-1); -} - -int32_t is_hexstr(char *str,int32_t n) -{ - int32_t i; - if ( str == 0 || str[0] == 0 ) - return(0); - for (i=0; str[i]!=0; i++) - { - if ( n > 0 && i >= n ) - break; - if ( _unhex(str[i]) < 0 ) - break; - } - if ( n == 0 ) - return(i); - return(i == n); -} - -int32_t unhex(char c) -{ - int32_t hex; - if ( (hex= _unhex(c)) < 0 ) - { - //printf("unhex: illegal hexchar.(%c)\n",c); - } - return(hex); -} - -unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } - -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) -{ - int32_t adjust,i = 0; - //printf("decode.(%s)\n",hex); - if ( is_hexstr(hex,n) <= 0 ) - { - memset(bytes,0,n); - return(n); - } - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) - { - if ( n > 0 ) - { - bytes[0] = unhex(hex[0]); - printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); - } - bytes++; - hex++; - adjust = 1; - } else adjust = 0; - if ( n > 0 ) - { - for (i=0; i>4) & 0xf); - hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); - //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); - } - hexbytes[len*2] = 0; - //printf("len.%ld\n",len*2+1); - return((int32_t)len*2+1); -} - -char *bits256_str(char hexstr[65],bits256 x) -{ - init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); - return(hexstr); -} - long _stripwhite(char *buf,int accept) { int32_t i,j,c; diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 65ddf1e514a..960316219c9 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -47,6 +47,7 @@ #include "extern.h" +#include "bits256.h" #undef lines @@ -351,12 +352,6 @@ #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) -#ifndef _BITS256 -#define _BITS256 -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; -#endif - #include "rogue_player.h" // interface to rpc struct rogue_state diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 679a6913a42..95b86adfe3f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -571,7 +571,7 @@ void *chainparams_commandline() pCurrentParams->SetNValue(ASSETCHAINS_NK[0]); pCurrentParams->SetKValue(ASSETCHAINS_NK[1]); } - if ( KOMODO_TESTNODE != 0 ) + if ( IS_KOMODO_TESTNODE ) pCurrentParams->SetMiningRequiresPeers(false); if ( ASSETCHAINS_RPCPORT == 0 ) ASSETCHAINS_RPCPORT = ASSETCHAINS_P2PPORT + 1; diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 0a081c0868a..4b1cae233f3 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -19,6 +19,7 @@ #include "main.h" #include "notarisationdb.h" #include "merkleblock.h" +#include "hex.h" #include "cc/CCinclude.h" diff --git a/src/hex.c b/src/hex.c new file mode 100644 index 00000000000..5e8c68b7c04 --- /dev/null +++ b/src/hex.c @@ -0,0 +1,140 @@ +#include +#include "hex.h" + +/*** + * turn a char into its hex value + * A '5' becomes a 5, 'B' (or 'b') becomes 11. + * @param c the input + * @returns the value + */ +int32_t unhex(char c) +{ + if ( c >= '0' && c <= '9' ) + return(c - '0'); + else if ( c >= 'a' && c <= 'f' ) + return(c - 'a' + 10); + else if ( c >= 'A' && c <= 'F' ) + return(c - 'A' + 10); + return(-1); +} + +/*** + * Check n characters of a string to see if it can be + * interpreted as a hex string + * @param str the input + * @param n the size of input to check, 0 to check until null terminator found + * @returns 0 on error, othewise a positive number + */ +int32_t is_hexstr(const char *str,int32_t n) +{ + int32_t i; + if ( str == 0 || str[0] == 0 ) + return(0); + for (i=0; str[i]!=0; i++) + { + if ( n > 0 && i >= n ) + break; + if ( unhex(str[i]) < 0 ) + break; + } + if ( n == 0 ) + return(i); + return(i == n); +} + +/*** + * Decode a 2 character hex string into its value + * @param hex the string (i.e. 'ff') + * @returns the value (i.e. 255) + */ +unsigned char _decode_hex(const char *hex) +{ + return (unhex(hex[0])<<4) | unhex(hex[1]); +} + +/*** + * Turn a hex string into bytes + * NOTE: If there is 1 extra character in a null-terminated str, treat the first char as a full byte + * + * @param bytes where to store the output (will be cleared if hex has invalid chars) + * @param n number of bytes to process + * @param hex the input (will ignore CR/LF) + * @returns the number of bytes processed + */ +int32_t decode_hex(uint8_t *bytes, int32_t n,const char *str) +{ + uint8_t extra = 0; + // check validity of input + if ( is_hexstr(str,n) <= 0 ) + { + memset(bytes,0,n); // give no results + return 0; + } + if (str[n*2+1] == 0 && str[n*2] != 0) + { + // special case: odd number of char, then null terminator + // treat first char as a whole byte + bytes[0] = unhex(str[0]); + extra = 1; + bytes++; + str++; + } + if ( n > 0 ) + { + for (int i=0; i>4) & 0xf); + hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); + } + hexbytes[len*2] = 0; + return((int32_t)len*2+1); +} + +/*** + * Convert a bits256 into a hex character string + * @param hexstr the results + * @param x the input + * @returns a pointer to hexstr + */ +char *bits256_str(char hexstr[65],bits256 x) +{ + init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); + return(hexstr); +} diff --git a/src/hex.h b/src/hex.h new file mode 100644 index 00000000000..1361c8bc0f2 --- /dev/null +++ b/src/hex.h @@ -0,0 +1,65 @@ +/*** + * Routines for char to hex conversions + */ +#pragma once +#include +#include "bits256.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/*** + * turn a char into its hex value + * A '5' becomes a 5, 'B' (or 'b') becomes 11. + * @param c the input + * @returns the value + */ +int32_t unhex(char c); + +/*** + * Check n characters of a string to see if it can be + * interpreted as a hex string + * @param str the input + * @param n the size of input to check, 0 to check until null terminator found + * @returns 0 on error, othewise a positive number + */ +int32_t is_hexstr(const char *str,int32_t n); + +/*** + * Decode a 2 character hex string into its value + * @param hex the string (i.e. 'ff') + * @returns the value (i.e. 255) + */ +unsigned char _decode_hex(const char *hex) ; + +/*** + * Turn a hex string into bytes + * @param bytes where to store the output + * @param n number of bytes to process + * @param hex the input (will ignore CR/LF) + * @returns the number of bytes processed (not an indicator of success) + */ +int32_t decode_hex(uint8_t *bytes, int32_t n,const char *in); + +/**** + * Convert a binary array of bytes into a hex string + * @param hexbytes the result + * @param message the array of bytes + * @param len the length of message + * @returns the length of hexbytes (including null terminator) + */ +int32_t init_hexbytes_noT(char *hexbytes, unsigned char *message, long len); + +/*** + * Convert a bits256 into a hex character string + * @param hexstr the results + * @param x the input + * @returns a pointer to hexstr + */ +char *bits256_str(char hexstr[65], bits256 x); + +#ifdef __cplusplus +} +#endif diff --git a/src/komodo.h b/src/komodo.h index 88e741df7f7..f37c9c28cb1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -547,13 +547,13 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { - if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && IS_KOMODO_NOTARY != 0 ) + if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && IS_KOMODO_NOTARY ) { printf("%s KOMODO_LASTMINED.%d -> %d\n",ASSETCHAINS_SYMBOL,KOMODO_LASTMINED,height); prevKOMODO_LASTMINED = KOMODO_LASTMINED; KOMODO_LASTMINED = height; } - decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); + decode_hex(crypto777,33,CRYPTO777_PUBSECPSTR); /*for (k=0; k<33; k++) printf("%02x",crypto777[k]); printf(" crypto777 "); @@ -835,7 +835,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } //fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight); // Wallet Filter. Disabled here. Cant be activated by notaries or pools with some changes. - if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 || IS_STAKED_NOTARY > -1 ) + if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 || STAKED_NOTARY_ID > -1 ) { staked_era = STAKED_era(pindex->GetBlockTime()); if ( !fJustCheck && staked_era != lastStakedEra ) @@ -937,26 +937,8 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) sp->NOTARIZED_HASH = block.GetHash(); sp->NOTARIZED_DESTTXID = txhash; } - //if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) - // printf("(tx.%d: ",i); for (j=0; j= 235300 && block.vtx[0].vout[1].nValue >= 100000*COIN ) - block.vtx[0].vout[1].nValue = 0; - break; - } - } - }*/ - //if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) - // printf("%.8f ",dstr(block.vtx[i].vout[j].nValue)); len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) ) @@ -976,8 +958,6 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } } } - //if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) - // printf(") "); if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification); if ( !fJustCheck && (notarized != 0 && (notarizedheight != 0 || specialtx != 0)) ) @@ -1018,7 +998,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } } } - if ( !fJustCheck && IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) + if ( !fJustCheck && IS_KOMODO_NOTARY && ASSETCHAINS_SYMBOL[0] == 0 ) printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height); if ( !fJustCheck && pindex->GetHeight() == hwmheight ) komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 137e0b16b3d..e8a8b5572a2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -574,34 +574,6 @@ CScript komodo_makeopret(CBlock *pblock, bool fNew) return(opret); } -/*uint256 komodo_getblockhash(int32_t height) - { - uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32]; - memset(&hash,0,sizeof(hash)); - sprintf(params,"[%d]",height); - if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,BITCOIND_RPCPORT)) != 0 ) - { - if ( (result= cJSON_Parse(jsonstr)) != 0 ) - { - if ( (hexstr= jstr(result,(char *)"result")) != 0 ) - { - if ( is_hexstr(hexstr,0) == 64 ) - { - decode_hex(revbuf,32,hexstr); - for (i=0; i<32; i++) - ((uint8_t *)&hash)[i] = revbuf[31-i]; - } - } - free_json(result); - } - printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash); - free(jsonstr); - } - return(hash); - } - - uint256 _komodo_getblockhash(int32_t height);*/ - uint64_t komodo_seed(int32_t height) { uint64_t seed = 0; @@ -827,7 +799,7 @@ int32_t komodo_is_notarytx(const CTransaction& tx) if ( ptr != 0 ) { if ( crypto777[0] == 0 ) - decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); + decode_hex(crypto777,33,CRYPTO777_PUBSECPSTR); if ( memcmp(ptr+1,crypto777,33) == 0 ) { //printf("found notarytx\n"); @@ -2282,7 +2254,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) } if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) { - decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(scripthex,scriptlen,ASSETCHAINS_SCRIPTPUB.c_str()); if ( memcmp(scripthex,script,scriptlen) == 0 ) matched = scriptlen; } @@ -2471,7 +2443,7 @@ int32_t komodo_checkPOW(int64_t stakeTxValue, int32_t slowflag,CBlock *pblock,in scriptlen = (int32_t)pblock->vtx[0].vout[0].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) { - decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(scripthex,scriptlen,ASSETCHAINS_SCRIPTPUB.c_str()); if ( memcmp(scripthex,script,scriptlen) != 0 ) return(-1); } else return(-1); @@ -2794,7 +2766,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt earliest = eligible; best_scriptPubKey = kp->scriptPubKey; *utxovaluep = (uint64_t)kp->nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); + decode_hex((uint8_t *)utxotxidp,32,kp->txid.GetHex().c_str()); *utxovoutp = kp->vout; *txtimep = kp->txtime; } diff --git a/src/komodo_cJSON.c b/src/komodo_cJSON.c index 10140ad0232..b5f6c24244a 100644 --- a/src/komodo_cJSON.c +++ b/src/komodo_cJSON.c @@ -28,6 +28,7 @@ #include "cJSON.h" #include "komodo_cJSON.h" #include "cJSON.c" +#include "hex.h" #ifndef DBL_EPSILON #define DBL_EPSILON 2.2204460492503131E-16 diff --git a/src/komodo_cJSON.h b/src/komodo_cJSON.h index 3586b5cbf5b..773367caa38 100644 --- a/src/komodo_cJSON.h +++ b/src/komodo_cJSON.h @@ -46,6 +46,7 @@ #include #include +#include "bits256.h" #include "cJSON.h" //#include "../crypto777/OS_portable.h" @@ -57,12 +58,6 @@ extern "C" { #endif -#ifndef _BITS256 -#define _BITS256 - union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; - typedef union _bits256 bits256; -#endif - /* Macros for creating things quickly. */ #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) diff --git a/src/komodo_curve25519.h b/src/komodo_curve25519.h index cba40561b8b..3991daf8378 100644 --- a/src/komodo_curve25519.h +++ b/src/komodo_curve25519.h @@ -20,6 +20,8 @@ #include #include #include +#include "bits256.h" + #ifdef _WIN32 #include #endif diff --git a/src/komodo_defs.h b/src/komodo_defs.h index b4b118a5760..51f1e717bae 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -491,7 +491,8 @@ extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD; extern uint64_t ASSETCHAINS_TIMELOCKGTE; extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOMODO_INITDONE; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED,KOMODO_NSPV; +extern bool IS_KOMODO_NOTARY; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED,KOMODO_NSPV; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; @@ -505,21 +506,23 @@ extern std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; extern uint256 KOMODO_EARLYTXID; -extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; +extern bool IS_KOMODO_DEALERNODE; +extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; extern uint32_t ASSETCHAINS_CC; extern std::string CCerror,ASSETCHAINS_CCLIB; extern uint8_t ASSETCHAINS_CCDISABLES[256]; extern int32_t USE_EXTERNAL_PUBKEY; extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; -extern int32_t KOMODO_EXCHANGEWALLET; +extern bool IS_MODE_EXCHANGEWALLET; extern int32_t VERUS_MIN_STAKEAGE; extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; extern char NOTARYADDRS[64][64]; extern char NOTARY_ADDRESSES[NUM_KMD_SEASONS][64][64]; -extern int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL,IS_STAKED_NOTARY,STAKED_ERA; +extern bool IS_KOMODO_TESTNODE; +extern int32_t KOMODO_SNAPSHOT_INTERVAL,STAKED_NOTARY_ID,STAKED_ERA; extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; extern int32_t ASSETCHAINS_STAKED_SPLIT_PERCENTAGE; int tx_height( const uint256 &hash ); diff --git a/src/komodo_events.h b/src/komodo_events.h index 5500a341eb2..a597affeb39 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -41,14 +41,14 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig { static uint32_t counter; int32_t verified=0; char *coin; struct komodo_event_notarized N; coin = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - if ( IS_KOMODO_NOTARY != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 ) + if ( IS_KOMODO_NOTARY && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 ) { if ( counter++ < 100 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); } else if ( strcmp(symbol,coin) == 0 ) { - if ( 0 && IS_KOMODO_NOTARY != 0 && verified != 0 ) + if ( 0 && IS_KOMODO_NOTARY && verified != 0 ) fprintf(stderr,"validated [%s] ht.%d notarized %d\n",coin,height,notarizedheight); memset(&N,0,sizeof(N)); N.blockhash = notarized_hash; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 063364230e5..c85b4acd1d6 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -55,7 +55,10 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; uint256 KOMODO_EARLYTXID; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV; +bool IS_KOMODO_NOTARY; +bool IS_MODE_EXCHANGEWALLET; +bool IS_KOMODO_DEALERNODE; +int32_t KOMODO_MININGTHREADS = -1,STAKED_NOTARY_ID,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; @@ -118,10 +121,11 @@ uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10,ASSETCHAINS_FOUNDERS_REW uint32_t KOMODO_INITDONE; char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771, DEST_PORT; uint64_t PENDING_KOMODO_TX; -extern int32_t KOMODO_LOADINGBLOCKS; +extern int32_t KOMODO_LOADINGBLOCKS; // defined in pow.cpp, boolean, 1 if currently loading the block index, 0 if not unsigned int MAX_BLOCK_SIGOPS = 20000; -int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; +bool IS_KOMODO_TESTNODE; +int32_t KOMODO_SNAPSHOT_INTERVAL; CScript KOMODO_EARLYTXID_SCRIPTPUB; int32_t ASSETCHAINS_EARLYTXIDCONTRACT; int32_t ASSETCHAINS_STAKED_SPLIT_PERCENTAGE; diff --git a/src/komodo_kv.h b/src/komodo_kv.h index a879340ffea..048794a89ef 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -17,6 +17,7 @@ #define H_KOMODOKV_H #include "komodo_defs.h" +#include "hex.h" int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) { diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index b17c7b104da..ea6156a5b2c 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -729,7 +729,7 @@ uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint2 if ( *txlenp > 0 ) { rawtx = (uint8_t *)calloc(1,*txlenp); - decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); + decode_hex(rawtx,*txlenp,strHex.c_str()); } } return(rawtx); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index f820e0bd568..69631987f8a 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -491,7 +491,7 @@ void komodo_init(int32_t height) if ( didinit == 0 ) { pthread_mutex_init(&komodo_mutex,NULL); - decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + decode_hex(NOTARY_PUBKEY33,33,NOTARY_PUBKEY.c_str()); if ( height >= 0 ) { n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); diff --git a/src/komodo_port.c b/src/komodo_port.c index fd68db881dd..f19018eebcc 100644 --- a/src/komodo_port.c +++ b/src/komodo_port.c @@ -17,6 +17,7 @@ #include #include #include +#include "bits256.h" uint64_t ASSETCHAINS_COMMISSION; uint32_t ASSETCHAINS_MAGIC = 2387029918; @@ -24,8 +25,6 @@ uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; struct sha256_vstate { uint64_t length; uint32_t state[8],curlen; uint8_t buf[64]; }; struct rmd160_vstate { uint64_t length; uint8_t buf[64]; uint32_t curlen, state[5]; }; -union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; -typedef union _bits256 bits256; // following is ported from libtom diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 6b7c316b6b9..8cf68918b91 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -48,14 +48,7 @@ #define KOMODO_KVDURATION 1440 #define KOMODO_ASSETCHAIN_MAXLEN 65 -#ifndef _BITS256 -#define _BITS256 - union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; - typedef union _bits256 bits256; -#endif - -union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; }; -typedef union _bits320 bits320; +#include "bits256.h" struct komodo_kv { UT_hash_handle hh; bits256 pubkey; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f21241cccc2..df559e15966 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -13,6 +13,7 @@ * * ******************************************************************************/ #include "komodo_defs.h" +#include "hex.h" #include "key_io.h" #include "cc/CCinclude.h" #include @@ -822,112 +823,6 @@ int32_t bitweight(uint64_t x) return(wt); } -int32_t _unhex(char c) -{ - if ( c >= '0' && c <= '9' ) - return(c - '0'); - else if ( c >= 'a' && c <= 'f' ) - return(c - 'a' + 10); - else if ( c >= 'A' && c <= 'F' ) - return(c - 'A' + 10); - return(-1); -} - -int32_t is_hexstr(char *str,int32_t n) -{ - int32_t i; - if ( str == 0 || str[0] == 0 ) - return(0); - for (i=0; str[i]!=0; i++) - { - if ( n > 0 && i >= n ) - break; - if ( _unhex(str[i]) < 0 ) - break; - } - if ( n == 0 ) - return(i); - return(i == n); -} - -int32_t unhex(char c) -{ - int32_t hex; - if ( (hex= _unhex(c)) < 0 ) - { - //printf("unhex: illegal hexchar.(%c)\n",c); - } - return(hex); -} - -unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); } - -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) -{ - int32_t adjust,i = 0; - //printf("decode.(%s)\n",hex); - if ( is_hexstr(hex,n) <= 0 ) - { - memset(bytes,0,n); - return(n); - } - if ( hex[n-1] == '\n' || hex[n-1] == '\r' ) - hex[--n] = 0; - if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) ) - { - if ( n > 0 ) - { - bytes[0] = unhex(hex[0]); - printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex)); - } - bytes++; - hex++; - adjust = 1; - } else adjust = 0; - if ( n > 0 ) - { - for (i=0; i>4) & 0xf); - hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); - //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); - } - hexbytes[len*2] = 0; - //printf("len.%ld\n",len*2+1); - return((int32_t)len*2+1); -} - -char *bits256_str(char hexstr[65],bits256 x) -{ - init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); - return(hexstr); -} - int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp) { int32_t i; uint64_t x; @@ -1695,37 +1590,44 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k) return(-1); } +/*** + * Parse command line arguments + * @param argv0 the arguments + */ void komodo_args(char *argv0) { - std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; - FILE *fp; uint64_t val; uint16_t port, dest_rpc_port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512] = {0}; CTransaction earlytx; uint256 hashBlock; + uint8_t extrabuf[32756], *extraptr = 0; + int32_t i; + int32_t n; + int32_t nonz=0; + int32_t extralen = 0; + uint64_t ccEnablesHeight[512] = {0}; std::string ntz_dest_path; ntz_dest_path = GetArg("-notary", ""); - IS_KOMODO_NOTARY = ntz_dest_path == "" ? 0 : 1; + IS_KOMODO_NOTARY = !ntz_dest_path.empty(); - - IS_STAKED_NOTARY = GetArg("-stakednotary", -1); + STAKED_NOTARY_ID = GetArg("-stakednotary", -1); KOMODO_NSPV = GetArg("-nSPV",0); - memset(ccenables,0,sizeof(ccenables)); + uint8_t disablebits[32]; memset(disablebits,0,sizeof(disablebits)); memset(ccEnablesHeight,0,sizeof(ccEnablesHeight)); if ( GetBoolArg("-gen", false) != 0 ) { KOMODO_MININGTHREADS = GetArg("-genproclimit",-1); } - if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) - fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); + if ( (IS_MODE_EXCHANGEWALLET = GetBoolArg("-exchange", false)) ) + fprintf(stderr,"IS_MODE_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); - KOMODO_DEALERNODE = GetArg("-dealer",0); - KOMODO_TESTNODE = GetArg("-testnode",0); + IS_KOMODO_DEALERNODE = GetBoolArg("-dealer",false); + IS_KOMODO_TESTNODE = GetArg("-testnode",0); ASSETCHAINS_STAKED_SPLIT_PERCENTAGE = GetArg("-splitperc",0); - if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) + if ( NOTARY_PUBKEY.size() == 66 ) { - decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + decode_hex(NOTARY_PUBKEY33,33,NOTARY_PUBKEY.c_str()); USE_EXTERNAL_PUBKEY = 1; - if ( IS_KOMODO_NOTARY == 0 ) + if ( !IS_KOMODO_NOTARY ) { // We dont have any chain data yet, so use system clock to guess. // I think on season change should reccomend notaries to use -notary to avoid needing this. @@ -1734,24 +1636,24 @@ void komodo_args(char *argv0) { if ( strcmp(NOTARY_PUBKEY.c_str(),notaries_elected[kmd_season-1][i][1]) == 0 ) { - IS_KOMODO_NOTARY = 1; + IS_KOMODO_NOTARY = true; KOMODO_MININGTHREADS = 1; mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); - IS_STAKED_NOTARY = -1; + STAKED_NOTARY_ID = -1; fprintf(stderr,"running as notary.%d %s\n",i,notaries_elected[kmd_season-1][i][0]); break; } } } } - if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) { + if ( STAKED_NOTARY_ID != -1 && IS_KOMODO_NOTARY ) { fprintf(stderr, "Cannot be STAKED and KMD notary at the same time!\n"); StartShutdown(); } - name = GetArg("-ac_name",""); + std::string name = GetArg("-ac_name",""); if ( argv0 != 0 ) { - len = (int32_t)strlen(argv0); + size_t len = strlen(argv0); for (i=0; i 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) - { - fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 + || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 + || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 + || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 + || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF + || ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 + || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 + || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 + || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 + || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 + || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) + { + fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100, + ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2], + (int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; @@ -2125,7 +2041,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_LWMAPOS),(void *)&ASSETCHAINS_LWMAPOS); } - val = ASSETCHAINS_COMMISSION | (((int64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; + uint64_t val = ASSETCHAINS_COMMISSION | (((int64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) @@ -2142,7 +2058,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { - decode_hex(&extraptr[extralen],ASSETCHAINS_SCRIPTPUB.size()/2,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(&extraptr[extralen],ASSETCHAINS_SCRIPTPUB.size()/2,ASSETCHAINS_SCRIPTPUB.c_str()); extralen += ASSETCHAINS_SCRIPTPUB.size()/2; //extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); fprintf(stderr,"append ac_script %s\n",ASSETCHAINS_SCRIPTPUB.c_str()); @@ -2161,7 +2077,7 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'c'; if ( ASSETCHAINS_MARMARA != 0 ) extraptr[extralen++] = ASSETCHAINS_MARMARA; -fprintf(stderr,"extralen.%d before disable bits\n",extralen); + fprintf(stderr,"extralen.%d before disable bits\n",extralen); if ( nonz > 0 ) { memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); @@ -2190,7 +2106,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); { for (i=0; i 0 ) + std::string addn = GetArg("-seednode",""); + if ( !addn.empty() ) ASSETCHAINS_SEED = 1; strncpy(ASSETCHAINS_SYMBOL,name.c_str(),sizeof(ASSETCHAINS_SYMBOL)-1); MAX_MONEY = komodo_max_money(); + int32_t baseid; if ( (baseid = komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 ) { - //komodo_maxallowed(baseid); printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); } @@ -2248,7 +2164,6 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); if ( KOMODO_BIT63SET(MAX_MONEY) != 0 ) MAX_MONEY = KOMODO_MAXNVALUE; fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); - //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); if ( GetArg("-port",0) != 0 ) { @@ -2256,7 +2171,8 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); } else ASSETCHAINS_P2PPORT = tmpport; - while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) + char *dirname; + while ( (dirname = (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { fprintf(stderr,"waiting for datadir (%s)\n",dirname); #ifndef _WIN32 @@ -2265,7 +2181,6 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); boost::this_thread::sleep(boost::posix_time::milliseconds(3000)); #endif } - //fprintf(stderr,"Got datadir.(%s)\n",dirname); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { int32_t komodo_baseid(char *origbase); @@ -2275,6 +2190,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); fprintf(stderr,"cant have assetchain named KMD\n"); StartShutdown(); } + uint16_t port; if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); @@ -2292,23 +2208,23 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); } if ( ASSETCHAINS_RPCPORT == 0 ) ASSETCHAINS_RPCPORT = ASSETCHAINS_P2PPORT + 1; - //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); - //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); + uint8_t magic[4]; iguana_rwnum(1,magic,sizeof(ASSETCHAINS_MAGIC),(void *)&ASSETCHAINS_MAGIC); - for (i=0; i<4; i++) - sprintf(&magicstr[i<<1],"%02x",magic[i]); - magicstr[8] = 0; #ifndef FROM_CLI - sprintf(fname,"%s_7776",ASSETCHAINS_SYMBOL); - if ( (fp= fopen(fname,"wb")) != 0 ) - { + std::string fname = std::string(ASSETCHAINS_SYMBOL) + "_7776"; + FILE* fp; + if ( (fp= fopen(fname.c_str(),"wb")) != 0 ) + { + char magicstr[9]; + for (i=0; i<4; i++) + sprintf(&magicstr[i<<1],"%02x",magic[i]); + magicstr[8] = 0; int8_t notarypay = 0; if ( ASSETCHAINS_NOTARY_PAY[0] != 0 ) notarypay = 1; fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),name.c_str(),name.c_str(),magicstr,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,"78.47.196.146",notarypay); fclose(fp); - //printf("created (%s)\n",fname); - } else printf("error creating (%s)\n",fname); + } else printf("error creating (%s)\n",fname.c_str()); #endif if ( ASSETCHAINS_CC < 2 ) { @@ -2326,7 +2242,9 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); } else { - char fname[512],username[512],password[4096]; int32_t iter; FILE *fp; + char fname[512],username[512],password[4096]; + int32_t iter; + FILE *fp; ASSETCHAINS_P2PPORT = 7770; ASSETCHAINS_RPCPORT = 7771; for (iter=0; iter<2; iter++) @@ -2353,12 +2271,12 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); #endif if ( (fp= fopen(fname,"rb")) != 0 ) { - dest_rpc_port = _komodo_userpass(username,password,fp); + uint16_t dest_rpc_port = _komodo_userpass(username,password,fp); DEST_PORT = iter == 1 ? dest_rpc_port : 0; sprintf(iter == 0 ? KMDUSERPASS : BTCUSERPASS,"%s:%s",username,password); fclose(fp); } else printf("couldnt open.(%s) will not validate dest notarizations\n",fname); - if ( IS_KOMODO_NOTARY == 0 ) + if ( !IS_KOMODO_NOTARY ) break; } } @@ -2366,7 +2284,6 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); - //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_RPCPORT); if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING[0] == 77777 ) { ASSETCHAINS_HALVING[0] *= 5; diff --git a/src/main.cpp b/src/main.cpp index 7d0d52424ed..b61d7bb79c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3803,7 +3803,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0].GetValueOut(), blockReward), REJECT_INVALID, "bad-cb-amount"); - } else if ( IS_KOMODO_NOTARY != 0 ) + } else if ( IS_KOMODO_NOTARY ) fprintf(stderr,"allow nHeight.%d coinbase %.8f vs %.8f interest %.8f\n",(int32_t)pindex->GetHeight(),dstr(block.vtx[0].GetValueOut()),dstr(blockReward),dstr(sum)); } if (!control.Wait()) @@ -6014,6 +6014,13 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes) return true; } +/**** + * Open a file + * @param pos where to position for the next read + * @param prefix the type of file (i.e. "blk", "rev", etc. + * @param fReadOnly open in read only mode + * @returns the file pointer or NULL on error + */ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) { static int32_t didinit[256]; @@ -6021,9 +6028,9 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) return NULL; boost::filesystem::path path = GetBlockPosFilename(pos, prefix); boost::filesystem::create_directories(path.parent_path()); - FILE* file = fopen(path.string().c_str(), "rb+"); + FILE* file = fopen(path.string().c_str(), "rb+"); // open existing file for reading and writing if (!file && !fReadOnly) - file = fopen(path.string().c_str(), "wb+"); + file = fopen(path.string().c_str(), "wb+"); // create an empty file for reading and writing if (!file) { LogPrintf("Unable to open file %s\n", path.string()); return NULL; @@ -6043,14 +6050,32 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) return file; } +/*** + * Open a block file + * @param pos where to position for the next read + * @param fReadOnly true to open the file in read only mode + * @returns the file pointer or NULL on error + */ FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly) { return OpenDiskFile(pos, "blk", fReadOnly); } +/*** + * Open an undo ("rev") file + * @param pos where to position for the next read + * @param fReadOnly true to open the file in read only mode + * @returns the file pointer or NULL on error + */ FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly) { return OpenDiskFile(pos, "rev", fReadOnly); } +/*** + * Get the full filename (including path) or a specific .dat file + * @param pos the block position + * @param prefix the prefix (i.e. "blk" or "rev") + * @returns the filename with the complete path + */ boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix) { return GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile); @@ -6543,6 +6568,10 @@ void UnloadBlockIndex() fHavePruned = false; } +/*** + * Load block index + * @returns true on success + */ bool LoadBlockIndex() { // Load block index from databases @@ -7728,12 +7757,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } pfrom->PushMessage("headers", vHeaders); } - /*else if ( IS_KOMODO_NOTARY != 0 ) - { - static uint32_t counter; - if ( counter++ < 3 ) - fprintf(stderr,"you can ignore redundant getheaders from peer.%d %d prev.%d\n",(int32_t)pfrom->id,(int32_t)(pindex ? pindex->GetHeight() : -1),pfrom->lasthdrsreq); - }*/ } diff --git a/src/miner.cpp b/src/miner.cpp index 95f1f166fe3..c8bd108f63e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -46,6 +46,8 @@ #include "ui_interface.h" #include "util.h" #include "utilmoneystr.h" +#include "hex.h" + #ifdef ENABLE_WALLET #include "wallet/wallet.h" #endif @@ -153,7 +155,6 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits uint256 komodo_calcmerkleroot(CBlock *pblock, uint256 prevBlockHash, int32_t nHeight, bool fNew, CScript scriptPubKey); int32_t komodo_newStakerActive(int32_t height, uint32_t timestamp); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void* ptr); -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t komodo_is_notarytx(const CTransaction& tx); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); @@ -724,7 +725,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); else txNew.nLockTime = std::max((int64_t)(pindexPrev->nTime+1), GetTime()); - if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; pblock->vtx[0] = txNew; @@ -756,7 +757,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 len >>= 1; txNew.vout[1].scriptPubKey.resize(len); ptr = (uint8_t *)&txNew.vout[1].scriptPubKey[0]; - decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); } else { @@ -857,7 +858,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY && My_notaryid >= 0 ) { uint32_t r; CScript opret; void **ptr=0; CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); @@ -904,7 +905,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } if ( ptr!=0 ) free(ptr); } - else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) ) + else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || !IS_KOMODO_NOTARY || My_notaryid < 0) ) { CValidationState state; //fprintf(stderr,"check validity\n"); @@ -1021,7 +1022,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, len >>= 1; scriptPubKey.resize(len); ptr = (uint8_t *)&scriptPubKey[0]; - decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); } } else if ( USE_EXTERNAL_PUBKEY != 0 ) @@ -1126,7 +1127,7 @@ static bool ProcessBlockFound(CBlock* pblock) #ifdef ENABLE_WALLET // Remove key from key pool - if ( IS_KOMODO_NOTARY == 0 ) + if ( !IS_KOMODO_NOTARY ) { if (GetArg("-mineraddress", "").empty()) { // Remove key from key pool @@ -1871,7 +1872,7 @@ void static BitcoinMiner() if ( i == 33 ) externalflag = 1; else externalflag = 0; - if ( IS_KOMODO_NOTARY != 0 ) + if ( IS_KOMODO_NOTARY ) { for (i=1; i<66; i++) if ( memcmp(pubkeys[i],pubkeys[0],33) == 0 ) @@ -1980,7 +1981,7 @@ void static BitcoinMiner() // MilliSleep(30); return false; } - if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetTime() ) + if ( IS_KOMODO_NOTARY && B.nTime > GetTime() ) { //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetTime() < B.nTime-2 ) @@ -1995,7 +1996,7 @@ void static BitcoinMiner() } if ( ASSETCHAINS_STAKED == 0 ) { - if ( IS_KOMODO_NOTARY != 0 ) + if ( IS_KOMODO_NOTARY ) { int32_t r; if ( (r= ((Mining_height + NOTARY_PUBKEY33[16]) % 64) / 8) > 0 ) diff --git a/src/net.cpp b/src/net.cpp index 5fe1660254f..111e7acdf90 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -467,13 +467,8 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -//fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); } - - - - std::map CNode::setBanned; CCriticalSection CNode::cs_setBanned; diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index db1696ed5ec..14b86cbc8a9 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -3,6 +3,7 @@ #include "crosschain.h" #include "cc/CCinclude.h" #include "komodo_defs.h" +#include "hex.h" #include extern pthread_mutex_t staked_mutex; @@ -81,7 +82,7 @@ int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) { if ( didinit[era-1] == 0 ) { for (i=0; i +#include "hex.h" + +namespace TestHex { + + TEST(TestHex, decodehex) + { + { + // n = 0 + char* in = (char*) "01"; + uint8_t bytes[2] = {0}; + ASSERT_EQ(decode_hex(bytes, 0, in), 0); + ASSERT_EQ(bytes[0], 0x00); + } + { + // happy path + char* in = (char*) "01"; + uint8_t bytes[1] = {0}; + ASSERT_EQ(decode_hex(bytes, 1, in), 1); + ASSERT_EQ(bytes[0], 0x01); + } + { + // cr/lf + char* in = (char*) "01\r\n"; + uint8_t bytes[1] = {0}; + ASSERT_EQ(decode_hex(bytes, 1, in), 1); + ASSERT_EQ(bytes[0], 0x01); + } + { + // string longer than what we say by 1 + // evidently a special case that we handle by treating + // the 1st char as a complete byte + char* in = (char*) "010"; + uint8_t bytes[2] = {0}; + ASSERT_EQ(decode_hex(bytes, 1, in), 2); + ASSERT_EQ(bytes[0], 0); + ASSERT_EQ(bytes[1], 16); + } + } + +} // namespace TestHex diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index f7717affa9c..a310adeb067 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -24,7 +24,7 @@ int32_t ASSETCHAINS_LWMAPOS = 0; int32_t VERUS_BLOCK_POSUNITS = 1000; int32_t ASSETCHAINS_OVERWINTER = 227520; int32_t ASSETCHAINS_SAPLING = 227520; -int32_t KOMODO_TESTNODE = 0; +bool IS_KOMODO_TESTNODE = false; unsigned int MAX_BLOCK_SIGOPS = 20000; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0d2e027b986..fb94b42434c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -60,6 +60,7 @@ #include #include "komodo_defs.h" +#include "hex.h" #include using namespace std; @@ -5489,7 +5490,6 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp, const CPubKey& m #include "script/sign.h" -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *pTr) @@ -5538,7 +5538,6 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void * continue; } utxovalue = (uint64_t)nValue; - //decode_hex((uint8_t *)&utxotxid,32,(char *)out.tx->GetHash().GetHex().c_str()); utxotxid = out.tx->GetHash(); utxovout = out.i; best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; @@ -5729,7 +5728,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (strlen(params[0].get_str().c_str()) == 66) { - decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); + decode_hex(pubkey33,33,params[0].get_str().c_str()); pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); CBitcoinAddress address(Raddress); bool isValid = address.IsValid(); @@ -5743,14 +5742,14 @@ UniValue setpubkey(const UniValue& params, bool fHelp, const CPubKey& mypk) { result.push_back(Pair("ismine", "true")); std::string notaryname; - if ( (IS_STAKED_NOTARY= StakedNotaryID(notaryname, Raddress)) > -1 ) + if ( (STAKED_NOTARY_ID= StakedNotaryID(notaryname, Raddress)) > -1 ) { result.push_back(Pair("IsNotary", notaryname)); - IS_KOMODO_NOTARY = 0; + IS_KOMODO_NOTARY = false; } } NOTARY_PUBKEY = params[0].get_str(); - decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + decode_hex(NOTARY_PUBKEY33,33,NOTARY_PUBKEY.c_str()); USE_EXTERNAL_PUBKEY = 1; NOTARY_ADDRESS = address.ToString(); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index db66de052c4..b37669b5dbb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3423,7 +3423,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const !IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) && (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) { - if ( KOMODO_EXCHANGEWALLET == 0 ) + if ( !IS_MODE_EXCHANGEWALLET ) { uint32_t locktime; int32_t txheight; CBlockIndex *tipindex; if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->GetHeight() >= 60000 ) @@ -3550,30 +3550,20 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coin.second); nValueRet += coin.first; - //if ( KOMODO_EXCHANGEWALLET == 0 ) - // *interestp += pcoin->vout[i].interest; return true; } else if (n < nTargetValue + CENT) { vValue.push_back(coin); nTotalLower += n; - //if ( KOMODO_EXCHANGEWALLET == 0 && count < sizeof(interests)/sizeof(*interests) ) - //{ - //fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN); - //interests[count++] = pcoin->vout[i].interest; - //} if ( nTotalLower > 4*nTargetValue + CENT ) { - //fprintf(stderr,"why bother with all the utxo if we have double what is needed?\n"); break; } } else if (n < coinLowestLarger.first) { coinLowestLarger = coin; - //if ( KOMODO_EXCHANGEWALLET == 0 ) - // lowest_interest = pcoin->vout[i].interest; } } @@ -3583,8 +3573,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; - //if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) - // *interestp += interests[i]; } return true; } @@ -3595,8 +3583,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return false; setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; - //if ( KOMODO_EXCHANGEWALLET == 0 ) - // *interestp += lowest_interest; return true; } @@ -3616,8 +3602,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; - //if ( KOMODO_EXCHANGEWALLET == 0 ) - // *interestp += lowest_interest; } else { for (unsigned int i = 0; i < vValue.size(); i++) @@ -3625,8 +3609,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; - //if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) - // *interestp += interests[i]; } LogPrint("selectcoins", "SelectCoins() best subset: "); @@ -3643,11 +3625,6 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set vCoinsNoCoinbase, vCoinsWithCoinbase; AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false); AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true); @@ -3665,7 +3642,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - if ( KOMODO_EXCHANGEWALLET == 0 ) + if ( !IS_MODE_EXCHANGEWALLET ) value += out.tx->vout[out.i].interest; } if (value <= nTargetValue) { @@ -3675,7 +3652,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - if ( KOMODO_EXCHANGEWALLET == 0 ) + if ( !IS_MODE_EXCHANGEWALLET ) valueWithCoinbase += out.tx->vout[out.i].interest; } fNeedCoinbaseCoinsRet = (valueWithCoinbase >= nTargetValue); @@ -3689,8 +3666,6 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - //if ( KOMODO_EXCHANGEWALLET == 0 ) - // *interestp += out.tx->vout[out.i].interest; setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); @@ -3712,7 +3687,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout.size() <= outpoint.n) return false; nValueFromPresetInputs += pcoin->vout[outpoint.n].nValue; - if ( KOMODO_EXCHANGEWALLET == 0 ) + if ( !IS_MODE_EXCHANGEWALLET ) nValueFromPresetInputs += pcoin->vout[outpoint.n].interest; setPresetCoins.insert(make_pair(pcoin, outpoint.n)); } else @@ -3929,7 +3904,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //a chance at a free transaction. //But mempool inputs might still be in the mempool, so their age stays 0 //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); - if ( KOMODO_EXCHANGEWALLET == 0 && ASSETCHAINS_SYMBOL[0] == 0 ) + if ( !IS_MODE_EXCHANGEWALLET && ASSETCHAINS_SYMBOL[0] == 0 ) { interest2 += pcoin.first->vout[pcoin.second].interest; //fprintf(stderr,"%.8f ",(double)pcoin.first->vout[pcoin.second].interest/COIN); @@ -3939,11 +3914,6 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt age += 1; dPriority += (double)nCredit * age; } - //if ( KOMODO_EXCHANGEWALLET != 0 ) - //{ - //fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); - //interest = 0; // interest2 also - //} if ( ASSETCHAINS_SYMBOL[0] == 0 && DONATION_PUBKEY.size() == 66 && interest2 > 5000 ) { CScript scriptDonation = CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG;