diff --git a/src/base58.cpp b/src/base58.cpp index ef5abc834..9a6945802 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -383,3 +383,16 @@ bool IsValidDestinationString(const std::string& str) { return IsValidDestinationString(str, Params()); } + +bool DecodeKevaNamespace(const std::string ns, const CChainParams& params, std::vector& result) +{ + if (!DecodeBase58Check(ns, result)) { + return false; + } + uint160 hash; + const std::vector& ns_prefix = params.Base58Prefix(CChainParams::KEVA_NAMESPACE); + if (result.size() == hash.size() + ns_prefix.size() && std::equal(ns_prefix.begin(), ns_prefix.end(), result.begin())) { + return true; + } + return false; +} diff --git a/src/base58.h b/src/base58.h index 39eb4eacc..32fcaffd3 100644 --- a/src/base58.h +++ b/src/base58.h @@ -146,5 +146,6 @@ std::string EncodeDestination(const CTxDestination& dest); CTxDestination DecodeDestination(const std::string& str); bool IsValidDestinationString(const std::string& str); bool IsValidDestinationString(const std::string& str, const CChainParams& params); +bool DecodeKevaNamespace(const std::string ns, const CChainParams& params, std::vector& result); #endif // BITCOIN_BASE58_H diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d19032a58..63af3eed3 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -50,6 +50,9 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi */ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) { + // JWU TODO: + // 1. Change timestamp + // 2. Fix coinbase script using segwit. const char* pszTimestamp = "NY Times 05/Oct/2011 Steve Jobs, Appleā€™s Visionary, Dies at 56"; const CScript genesisOutputScript = CScript() << ParseHex("049451c9ac3be691a4fa375ea69537a46ef374c1f454dbc7c2c6fe27b280f2b979991aadb29358591a1f72c326b537d7fd03e14d4978a1b57486d9e6d2c3645717") << OP_CHECKSIG; return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward); @@ -159,6 +162,7 @@ public: base58Prefixes[SECRET_KEY] = std::vector(1,139); // M base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E}; base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4}; + base58Prefixes[KEVA_NAMESPACE] = std::vector(1,53); // N bech32_hrp = "kva"; @@ -285,6 +289,7 @@ public: base58Prefixes[SECRET_KEY] = std::vector(1,239); base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF}; base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94}; + base58Prefixes[KEVA_NAMESPACE] = std::vector(1,53); // N bech32_hrp = "tkva"; @@ -402,6 +407,7 @@ public: base58Prefixes[SECRET_KEY] = std::vector(1,239); base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF}; base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94}; + base58Prefixes[KEVA_NAMESPACE] = std::vector(1,53); // N bech32_hrp = "rkva"; } diff --git a/src/chainparams.h b/src/chainparams.h index a52343477..3510ebc2e 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -48,6 +48,7 @@ public: SECRET_KEY, EXT_PUBLIC_KEY, EXT_SECRET_KEY, + KEVA_NAMESPACE, MAX_BASE58_TYPES }; diff --git a/src/keva/main.cpp b/src/keva/main.cpp index deb2cce39..f40c73316 100644 --- a/src/keva/main.cpp +++ b/src/keva/main.cpp @@ -153,7 +153,8 @@ CKevaMemPool::removeConflicts(const CTransaction& tx) bool CKevaMemPool::validateNamespace(const CTransaction& tx, const valtype& nameSpace) const { valtype kevaNamespace = ToByteVector(Hash160(ToByteVector(tx.vin[0].prevout.hash))); - kevaNamespace.insert(kevaNamespace.begin(), CKevaScript::NAMESPACE_PREFIX); + const std::vector& ns_prefix = Params().Base58Prefix(CChainParams::KEVA_NAMESPACE); + kevaNamespace.insert(kevaNamespace.begin(), ns_prefix.begin(), ns_prefix.end()); return kevaNamespace == nameSpace; } diff --git a/src/script/keva.cpp b/src/script/keva.cpp index 0559b6d97..5f2fa7786 100644 --- a/src/script/keva.cpp +++ b/src/script/keva.cpp @@ -8,8 +8,6 @@ const std::string CKevaScript::KEVA_DISPLAY_NAME_KEY = "_KEVA_NS_"; -const unsigned char CKevaScript::NAMESPACE_PREFIX = 53; // N in Base58Check - CKevaScript::CKevaScript (const CScript& script) : op(OP_NOP), address(script) { @@ -87,7 +85,7 @@ CScript CKevaScript::buildKevaNamespace(const CScript& addr, const valtype& name return prefix + addr; } -CScript CKevaScript::replaceKevaNamespace(const CScript& oldScript, const uint256& txId, valtype& kaveNamespace) +CScript CKevaScript::replaceKevaNamespace(const CScript& oldScript, const uint256& txId, valtype& kaveNamespace, const CChainParams& params) { CKevaScript kevaOp(oldScript); if (!kevaOp.isNamespaceRegistration()) { @@ -97,7 +95,9 @@ CScript CKevaScript::replaceKevaNamespace(const CScript& oldScript, const uint25 const valtype& displayName = kevaOp.getOpNamespaceDisplayName(); kaveNamespace = ToByteVector(Hash160(ToByteVector(txId))); - kaveNamespace.insert(kaveNamespace.begin(), NAMESPACE_PREFIX); + + const std::vector& ns_prefix = params.Base58Prefix(CChainParams::KEVA_NAMESPACE); + kaveNamespace.insert(kaveNamespace.begin(), ns_prefix.begin(), ns_prefix.end()); return CKevaScript::buildKevaNamespace(kevaOp.getAddress(), kaveNamespace, displayName); } diff --git a/src/script/keva.h b/src/script/keva.h index c1c222620..ee7842051 100644 --- a/src/script/keva.h +++ b/src/script/keva.h @@ -6,6 +6,7 @@ #define H_BITCOIN_SCRIPT_KEVA #include +#include #include