diff --git a/Conversion.cpp b/Conversion.cpp index 3c11bb958d..6f513be9f9 100644 --- a/Conversion.cpp +++ b/Conversion.cpp @@ -36,4 +36,18 @@ bool u160ToHuman(uint160& buf, std::string& retStr) { retStr=EncodeBase58(buf.begin(),buf.end()); return(true); -} \ No newline at end of file +} + +uint160 uint256::to160() const +{ + uint160 m; + memcpy(&m, this, sizeof(uint160)); + return m; +} + +uint256 uint160::to256() const +{ + uint256 m; + memcpy(&m, this, sizeof(this)); + return m; +} diff --git a/Ledger.cpp b/Ledger.cpp index 93ab2749aa..ac6282f4b3 100644 --- a/Ledger.cpp +++ b/Ledger.cpp @@ -67,7 +67,7 @@ AccountState::pointer Ledger::getAccountState(const uint160& accountID) std::cerr << "Ledger:getAccountState(" << accountID.GetHex() << ")" << std::endl; #endif ScopedLock l(mTransactionMap->Lock()); - SHAMapItem::pointer item=mAccountStateMap->peekItem(uint160to256(accountID)); + SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.to256()); if(!item) { #ifdef DEBUG @@ -81,7 +81,7 @@ AccountState::pointer Ledger::getAccountState(const uint160& accountID) uint64 Ledger::getBalance(const uint160& accountID) { ScopedLock l(mTransactionMap->Lock()); - SHAMapItem::pointer item=mAccountStateMap->peekItem(uint160to256(accountID)); + SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.to256()); if(!item) return 0; return AccountState(item->getData()).getBalance(); } diff --git a/SHAMap.cpp b/SHAMap.cpp index cc59e9cf36..6773e81318 100644 --- a/SHAMap.cpp +++ b/SHAMap.cpp @@ -178,7 +178,7 @@ SHAMapItem::SHAMapItem(const uint256& tag, const std::vector& dat { ; } SHAMapItem::SHAMapItem(const uint160& tag, const std::vector& data) - : mTag(uint160to256(tag)), mData(data) + : mTag(tag.to256()), mData(data) { ; } SHAMapItem::pointer SHAMap::peekFirstItem() diff --git a/SHAMap.h b/SHAMap.h index 54ad7ced28..86264c2179 100644 --- a/SHAMap.h +++ b/SHAMap.h @@ -278,8 +278,8 @@ public: SHAMapItem::pointer peekNextItem(const uint256&); SHAMapItem::pointer peekPrevItem(const uint256&); - SHAMapItem::pointer peekPrevItem(const uint160& u) { return peekPrevItem(uint160to256(u)); } - SHAMapItem::pointer peekNextItem(const uint160& u) { return peekNextItem(uint160to256(u)); } + SHAMapItem::pointer peekPrevItem(const uint160& u) { return peekPrevItem(u.to256()); } + SHAMapItem::pointer peekNextItem(const uint160& u) { return peekNextItem(u.to256()); } // comparison/sync functions void getMissingNodes(std::vector& nodeHashes, int max); diff --git a/uint256.h b/uint256.h index 6b15b1642c..0f79ff8557 100644 --- a/uint256.h +++ b/uint256.h @@ -468,6 +468,8 @@ public: else *this = 0; } + + uint256 to256() const; }; inline bool operator==(const uint160& a, uint64 b) { return (base_uint160)a == b; } @@ -582,6 +584,8 @@ public: else *this = 0; } + + uint160 to160() const; }; @@ -634,27 +638,6 @@ inline const uint256 operator|(const uint256& a, const uint256& b) { return (b inline const uint256 operator+(const uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; } inline const uint256 operator-(const uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; } -static uint256 uint160to256(const uint160& u) -{ - uint256 m; - memcpy(&m, &u, sizeof(u)); - return m; -} - -static uint160 uint256to160(const uint256& u) -{ - uint160 m; - memcpy(&m, &u, sizeof(m)); - return m; -} - - - - - - - - inline int Testuint256AdHoc(std::vector vArg) {