diff --git a/src/NewcoinAddress.cpp b/src/NewcoinAddress.cpp index f31036963e..d80e9254f4 100644 --- a/src/NewcoinAddress.cpp +++ b/src/NewcoinAddress.cpp @@ -58,7 +58,7 @@ void NewcoinAddress::clear() // NodePublic // -NewcoinAddress NewcoinAddress::createNodePublic(NewcoinAddress& naSeed) +NewcoinAddress NewcoinAddress::createNodePublic(const NewcoinAddress& naSeed) { CKey ckSeed(naSeed.getFamilySeed()); NewcoinAddress naNew; @@ -69,6 +69,29 @@ NewcoinAddress NewcoinAddress::createNodePublic(NewcoinAddress& naSeed) return naNew; } +NewcoinAddress NewcoinAddress::createNodePublic(const std::vector& vPublic) +{ + NewcoinAddress naNew; + + naNew.setNodePublic(vPublic); + + return naNew; +} + +uint160 NewcoinAddress::getNodeID() const +{ + switch (nVersion) { + case VER_NONE: + throw std::runtime_error("unset source"); + + case VER_NODE_PUBLIC: + // Note, we are encoding the left. + return Hash160(vchData); + + default: + throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion))); + } +} const std::vector& NewcoinAddress::getNodePublic() const { switch (nVersion) { @@ -136,7 +159,7 @@ bool NewcoinAddress::verifyNodePublic(const uint256& hash, const std::string& st // NodePrivate // -NewcoinAddress NewcoinAddress::createNodePrivate(NewcoinAddress& naSeed) +NewcoinAddress NewcoinAddress::createNodePrivate(const NewcoinAddress& naSeed) { uint256 uPrivKey; NewcoinAddress naNew; @@ -229,7 +252,7 @@ uint160 NewcoinAddress::getAccountID() const return uint160(vchData); case VER_ACCOUNT_PUBLIC: - // Note, we are encoding the left or right. + // Note, we are encoding the left. return Hash160(vchData); default: @@ -595,13 +618,6 @@ void NewcoinAddress::setFamilyGenerator(const std::vector& vPubli SetData(VER_FAMILY_GENERATOR, vPublic); } -#if 0 -void NewcoinAddress::setFamilyGenerator(const NewcoinAddress& seed) -{ - seed.seedInfo(this, 0); -} -#endif - NewcoinAddress NewcoinAddress::createGeneratorPublic(const NewcoinAddress& naSeed) { CKey ckSeed(naSeed.getFamilySeed()); @@ -616,21 +632,6 @@ NewcoinAddress NewcoinAddress::createGeneratorPublic(const NewcoinAddress& naSee // Family Seed // -#if 0 -// --> dstGenerator: Set the public generator from our seed. -void NewcoinAddress::seedInfo(NewcoinAddress* dstGenerator, BIGNUM** dstPrivateKey) const -{ - CKey pubkey = CKey(getFamilySeed()); - - if (dstGenerator) { - dstGenerator->setFamilyGenerator(pubkey.GetPubKey()); - } - - if (dstPrivateKey) - *dstPrivateKey = pubkey.GetSecretBN(); -} -#endif - uint128 NewcoinAddress::getFamilySeed() const { switch (nVersion) { @@ -645,17 +646,6 @@ uint128 NewcoinAddress::getFamilySeed() const } } -#if 0 -BIGNUM* NewcoinAddress::getFamilyPrivateKey() const -{ - BIGNUM* ret; - - seedInfo(0, &ret); - - return ret; -} -#endif - std::string NewcoinAddress::humanFamilySeed1751() const { switch (nVersion) { diff --git a/src/NewcoinAddress.h b/src/NewcoinAddress.h index 284e35c680..be0938d939 100644 --- a/src/NewcoinAddress.h +++ b/src/NewcoinAddress.h @@ -7,6 +7,7 @@ // // Used to hold addresses and parse and produce human formats. // +// XXX This needs to be reworked to store data in uint160 and uint256. Conversion to CBase58Data should happen as needed. class NewcoinAddress : public CBase58Data { private: @@ -21,8 +22,6 @@ private: VER_FAMILY_SEED = 33, } VersionEncoding; -// void seedInfo(NewcoinAddress* dstGenerator, BIGNUM** dstPrivateKey) const; - public: NewcoinAddress(); @@ -31,8 +30,9 @@ public: void clear(); // - // Node Public + // Node Public - Also used for Validators // + uint160 getNodeID() const; const std::vector& getNodePublic() const; std::string humanNodePublic() const; @@ -42,7 +42,8 @@ public: bool verifyNodePublic(const uint256& hash, const std::vector& vchSig) const; bool verifyNodePublic(const uint256& hash, const std::string& strSig) const; - static NewcoinAddress createNodePublic(NewcoinAddress& naSeed); + static NewcoinAddress createNodePublic(const NewcoinAddress& naSeed); + static NewcoinAddress createNodePublic(const std::vector& vPublic); // // Node Private @@ -57,7 +58,7 @@ public: void setNodePrivate(uint256 hash256); void signNodePrivate(const uint256& hash, std::vector& vchSig) const; - static NewcoinAddress createNodePrivate(NewcoinAddress& naSeed); + static NewcoinAddress createNodePrivate(const NewcoinAddress& naSeed); // // Accounts IDs @@ -159,7 +160,6 @@ public: // Family Seeds // Clients must disallow reconizable entries from being seeds. uint128 getFamilySeed() const; - // BIGNUM* getFamilyPrivateKey() const; std::string humanFamilySeed() const; std::string humanFamilySeed1751() const;