From 5b9439689043107110dee6ea4939db16e29e115d Mon Sep 17 00:00:00 2001 From: MJK Date: Thu, 27 Sep 2012 17:01:27 -0700 Subject: [PATCH] Move around to256 to uint256.h, get rid of Conversion.cpp,h --- src/Conversion.cpp | 50 ----------- src/Conversion.h | 11 --- src/Ledger.cpp | 1 - src/LedgerMaster.cpp | 1 - src/Peer.cpp | 1 - src/RPCServer.cpp | 10 +-- src/UniqueNodeList.cpp | 1 - src/uint256.h | 187 +++++++++++++++++++++-------------------- 8 files changed, 100 insertions(+), 162 deletions(-) delete mode 100644 src/Conversion.cpp delete mode 100644 src/Conversion.h diff --git a/src/Conversion.cpp b/src/Conversion.cpp deleted file mode 100644 index 7f9de9029b..0000000000 --- a/src/Conversion.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Conversion.h" -#include "base58.h" -using namespace std; - -#if 0 - -uint160 protobufTo160(const std::string& buf) -{ - uint160 ret; - // TODO: - return(ret); -} - -uint256 protobufTo256(const std::string& hash) -{ - uint256 ret; - // TODO: - return(ret); -} - -uint160 humanTo160(const std::string& buf) -{ - vector retVec; - DecodeBase58(buf,retVec); - uint160 ret; - memcpy(ret.begin(), &retVec[0], ret.GetSerializeSize()); - - - return(ret); -} - -bool humanToPK(const std::string& buf,std::vector& retVec) -{ - return(DecodeBase58(buf,retVec)); -} - -bool u160ToHuman(uint160& buf, std::string& retStr) -{ - retStr=EncodeBase58(buf.begin(),buf.end()); - return(true); -} - -#endif - -base_uint256 uint160::to256() const -{ - uint256 m; - memcpy(m.begin(), begin(), size()); - return m; -} diff --git a/src/Conversion.h b/src/Conversion.h deleted file mode 100644 index c2ceb5339a..0000000000 --- a/src/Conversion.h +++ /dev/null @@ -1,11 +0,0 @@ -#include "uint256.h" -#include - -extern uint160 protobufTo160(const std::string& buf); -extern uint256 protobufTo256(const std::string& hash); -extern uint160 humanTo160(const std::string& buf); -extern bool humanToPK(const std::string& buf,std::vector& retVec); - - -extern bool u160ToHuman(uint160& buf, std::string& retStr); - diff --git a/src/Ledger.cpp b/src/Ledger.cpp index e650f9b94f..8d7dec92bf 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -13,7 +13,6 @@ #include "../obj/src/newcoin.pb.h" #include "PackedMessage.h" #include "Config.h" -#include "Conversion.h" #include "BitcoinUtil.h" #include "Wallet.h" #include "LedgerTiming.h" diff --git a/src/LedgerMaster.cpp b/src/LedgerMaster.cpp index abdbf12e99..e0adb16ade 100644 --- a/src/LedgerMaster.cpp +++ b/src/LedgerMaster.cpp @@ -5,7 +5,6 @@ #include "Application.h" #include "NewcoinAddress.h" -#include "Conversion.h" #include "Log.h" uint32 LedgerMaster::getCurrentLedgerIndex() diff --git a/src/Peer.cpp b/src/Peer.cpp index ea27e06c81..641a33571c 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -12,7 +12,6 @@ #include "Peer.h" #include "Config.h" #include "Application.h" -#include "Conversion.h" #include "SerializedTransaction.h" #include "utils.h" #include "Log.h" diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 7f44f1fe58..202f0e5e3d 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -6,7 +6,6 @@ #include "Application.h" #include "RPC.h" #include "Wallet.h" -#include "Conversion.h" #include "NewcoinAddress.h" #include "AccountState.h" #include "NicknameState.h" @@ -15,9 +14,6 @@ #include "RippleLines.h" #include "Pathfinder.h" -#include "Conversion.h" - -extern uint160 humanTo160(const std::string& buf); #include @@ -1783,7 +1779,7 @@ Json::Value RPCServer::doSend(const Json::Value& params) // Destination exists, ordinary send. STPathSet spsPaths; - + /* uint160 srcCurrencyID; bool ret_b; ret_b = false; @@ -1793,7 +1789,7 @@ Json::Value RPCServer::doSend(const Json::Value& params) ret_b = pf.findPaths(5, 1, spsPaths); // TODO: Nope; the above can't be right - + */ trans = Transaction::sharedPayment( naAccountPublic, naAccountPrivate, naSrcAccountID, @@ -2544,7 +2540,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params { "data_fetch", &RPCServer::doDataFetch, 1, 1, true }, { "data_store", &RPCServer::doDataStore, 2, 2, true }, { "ledger", &RPCServer::doLedger, 0, 2, false, optNetwork }, - { "logrotate", &RPCServer::doLogRotate, 0, 0, true, optCurrent }, + { "logrotate", &RPCServer::doLogRotate, 0, 0, false, optCurrent }, { "nickname_info", &RPCServer::doNicknameInfo, 1, 1, false, optCurrent }, { "nickname_set", &RPCServer::doNicknameSet, 2, 3, false, optCurrent }, { "offer_create", &RPCServer::doOfferCreate, 9, 10, false, optCurrent }, diff --git a/src/UniqueNodeList.cpp b/src/UniqueNodeList.cpp index b5b1d2c804..96ca1b7d7d 100644 --- a/src/UniqueNodeList.cpp +++ b/src/UniqueNodeList.cpp @@ -2,7 +2,6 @@ // XXX Want a limit of 2000 validators. #include "Application.h" -#include "Conversion.h" #include "HttpsClient.h" #include "Log.h" #include "ParseSection.h" diff --git a/src/uint256.h b/src/uint256.h index bb11b101b4..3e2ab10e62 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -386,96 +386,6 @@ public: }; -////////////////////////////////////////////////////////////////////////////// -// -// uint160 -// - -class uint160 : public base_uint160 -{ -public: - typedef base_uint160 basetype; - - uint160() - { - zero(); - } - - uint160(const basetype& b) - { - *this = b; - } - - uint160& operator=(const basetype& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - - return *this; - } - - uint160(uint64 b) - { - *this = b; - } - - uint160& operator=(uint64 uHost) - { - zero(); - - // Put in least significant bits. - ((uint64_t *) end())[-1] = htobe64(uHost); - - return *this; - } - - explicit uint160(const std::string& str) - { - SetHex(str); - } - - explicit uint160(const std::vector& vch) - { - if (vch.size() == sizeof(pn)) - memcpy(pn, &vch[0], sizeof(pn)); - else - zero(); - } - - base_uint256 to256() const; -}; - -inline bool operator==(const uint160& a, uint64 b) { return (base_uint160)a == b; } -inline bool operator!=(const uint160& a, uint64 b) { return (base_uint160)a != b; } - -inline const uint160 operator^(const base_uint160& a, const base_uint160& b) { return uint160(a) ^= b; } -inline const uint160 operator&(const base_uint160& a, const base_uint160& b) { return uint160(a) &= b; } -inline const uint160 operator|(const base_uint160& a, const base_uint160& b) { return uint160(a) |= b; } - -inline bool operator==(const base_uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const base_uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const base_uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const base_uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const base_uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } - -inline bool operator==(const uint160& a, const base_uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const uint160& a, const base_uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const uint160& a, const base_uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const uint160& a, const base_uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const uint160& a, const base_uint160& b) { return (base_uint160)a | (base_uint160)b; } -inline bool operator==(const uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } -inline bool operator!=(const uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } -inline const uint160 operator^(const uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } -inline const uint160 operator&(const uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } -inline const uint160 operator|(const uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } - -extern std::size_t hash_value(const uint160&); - -inline const std::string strHex(const uint160& ui) -{ - return strHex(ui.begin(), ui.size()); -} - ////////////////////////////////////////////////////////////////////////////// // // uint256 @@ -694,5 +604,102 @@ inline int Testuint256AdHoc(std::vector vArg) return (0); } +////////////////////////////////////////////////////////////////////////////// +// +// uint160 +// + +class uint160 : public base_uint160 +{ +public: + typedef base_uint160 basetype; + + uint160() + { + zero(); + } + + uint160(const basetype& b) + { + *this = b; + } + + uint160& operator=(const basetype& b) + { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + + return *this; + } + + uint160(uint64 b) + { + *this = b; + } + + uint160& operator=(uint64 uHost) + { + zero(); + + // Put in least significant bits. + ((uint64_t *) end())[-1] = htobe64(uHost); + + return *this; + } + + explicit uint160(const std::string& str) + { + SetHex(str); + } + + explicit uint160(const std::vector& vch) + { + if (vch.size() == sizeof(pn)) + memcpy(pn, &vch[0], sizeof(pn)); + else + zero(); + } + + base_uint256 to256() const + { + uint256 m; + memcpy(m.begin(), begin(), size()); + return m; + } + +}; + +inline bool operator==(const uint160& a, uint64 b) { return (base_uint160)a == b; } +inline bool operator!=(const uint160& a, uint64 b) { return (base_uint160)a != b; } + +inline const uint160 operator^(const base_uint160& a, const base_uint160& b) { return uint160(a) ^= b; } +inline const uint160 operator&(const base_uint160& a, const base_uint160& b) { return uint160(a) &= b; } +inline const uint160 operator|(const base_uint160& a, const base_uint160& b) { return uint160(a) |= b; } + +inline bool operator==(const base_uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } +inline bool operator!=(const base_uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } +inline const uint160 operator^(const base_uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } +inline const uint160 operator&(const base_uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } +inline const uint160 operator|(const base_uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } + +inline bool operator==(const uint160& a, const base_uint160& b) { return (base_uint160)a == (base_uint160)b; } +inline bool operator!=(const uint160& a, const base_uint160& b) { return (base_uint160)a != (base_uint160)b; } +inline const uint160 operator^(const uint160& a, const base_uint160& b) { return (base_uint160)a ^ (base_uint160)b; } +inline const uint160 operator&(const uint160& a, const base_uint160& b) { return (base_uint160)a & (base_uint160)b; } +inline const uint160 operator|(const uint160& a, const base_uint160& b) { return (base_uint160)a | (base_uint160)b; } +inline bool operator==(const uint160& a, const uint160& b) { return (base_uint160)a == (base_uint160)b; } +inline bool operator!=(const uint160& a, const uint160& b) { return (base_uint160)a != (base_uint160)b; } +inline const uint160 operator^(const uint160& a, const uint160& b) { return (base_uint160)a ^ (base_uint160)b; } +inline const uint160 operator&(const uint160& a, const uint160& b) { return (base_uint160)a & (base_uint160)b; } +inline const uint160 operator|(const uint160& a, const uint160& b) { return (base_uint160)a | (base_uint160)b; } + +extern std::size_t hash_value(const uint160&); + +inline const std::string strHex(const uint160& ui) +{ + return strHex(ui.begin(), ui.size()); +} + + #endif // vim:ts=4