mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'pay'
Conflicts: src/LedgerMaster.h
This commit is contained in:
@@ -16,7 +16,7 @@ bool STAmount::currencyFromString(uint160& uDstCurrency, const std::string& sCur
|
||||
|
||||
if (sCurrency.empty() || !sCurrency.compare(SYSTEM_CURRENCY_CODE))
|
||||
{
|
||||
uDstCurrency = 0;
|
||||
uDstCurrency.zero();
|
||||
}
|
||||
else if (3 == sCurrency.size())
|
||||
{
|
||||
@@ -219,17 +219,22 @@ void STAmount::add(Serializer& s) const
|
||||
if (mIsNative)
|
||||
{
|
||||
assert(mOffset == 0);
|
||||
if (!mIsNegative) s.add64(mValue | cPosNative);
|
||||
else s.add64(mValue);
|
||||
return;
|
||||
if (!mIsNegative)
|
||||
s.add64(mValue | cPosNative);
|
||||
else
|
||||
s.add64(mValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isZero())
|
||||
s.add64(cNotNative);
|
||||
else if (mIsNegative) // 512 = not native
|
||||
s.add64(mValue | (static_cast<uint64>(mOffset + 512 + 97) << (64 - 10)));
|
||||
else // 256 = positive
|
||||
s.add64(mValue | (static_cast<uint64>(mOffset + 512 + 256 + 97) << (64 - 10)));
|
||||
|
||||
s.add160(mCurrency);
|
||||
}
|
||||
if (isZero())
|
||||
s.add64(cNotNative);
|
||||
else if (mIsNegative) // 512 = not native
|
||||
s.add64(mValue | (static_cast<uint64>(mOffset + 512 + 97) << (64 - 10)));
|
||||
else // 256 = positive
|
||||
s.add64(mValue | (static_cast<uint64>(mOffset + 512 + 256 + 97) << (64 - 10)));
|
||||
s.add160(mCurrency);
|
||||
}
|
||||
|
||||
STAmount::STAmount(const char* name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true)
|
||||
@@ -763,20 +768,25 @@ STAmount convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 t
|
||||
return STAmount(name, muldiv(displayAmount, totalNow, totalInit));
|
||||
}
|
||||
|
||||
STAmount STAmount::deSerialize(SerializerIterator& it)
|
||||
STAmount STAmount::deserialize(SerializerIterator& it)
|
||||
{
|
||||
STAmount *s = construct(it);
|
||||
STAmount ret(*s);
|
||||
|
||||
delete s;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static STAmount serdes(const STAmount &s)
|
||||
{
|
||||
Serializer ser;
|
||||
|
||||
s.add(ser);
|
||||
|
||||
SerializerIterator sit(ser);
|
||||
return STAmount::deSerialize(sit);
|
||||
|
||||
return STAmount::deserialize(sit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,19 +46,16 @@ LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SerializedLedgerEntry
|
||||
SerializedLedgerEntry::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
|
||||
LedgerEntryType let )
|
||||
{
|
||||
std::cerr << "getASNode>" << nodeID.ToString() << std::endl;
|
||||
SHAMapItem::pointer account = mAccountStateMap->peekItem(nodeID);
|
||||
std::cerr << "getASNode: d: " << nodeID.ToString() << std::endl;
|
||||
|
||||
if (!account)
|
||||
{
|
||||
if ( (parms & lepCREATE) == 0 )
|
||||
{
|
||||
parms = lepMISSING;
|
||||
std::cerr << "getASNode: missing: " << nodeID.ToString() << std::endl;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
|
||||
std::cerr << "getASNode: c: " << nodeID.ToString() << std::endl;
|
||||
parms = parms | lepCREATED | lepOKAY;
|
||||
SerializedLedgerEntry::pointer sle=boost::make_shared<SerializedLedgerEntry>(let);
|
||||
sle->setIndex(nodeID);
|
||||
@@ -66,21 +63,16 @@ std::cerr << "getASNode: c: " << nodeID.ToString() << std::endl;
|
||||
return sle;
|
||||
}
|
||||
|
||||
std::cerr << "getASNode: a: " << nodeID.ToString() << std::endl;
|
||||
std::cerr << "getASNode: e: " << strHex(account->peekSerializer().getData()) << std::endl;
|
||||
SerializedLedgerEntry::pointer sle =
|
||||
boost::make_shared<SerializedLedgerEntry>(account->peekSerializer(), nodeID);
|
||||
|
||||
std::cerr << "getASNode: b: " << nodeID.ToString() << std::endl;
|
||||
if(sle->getType() != let)
|
||||
{ // maybe it's a currency or something
|
||||
std::cerr << "getASNode: wrong type: " << nodeID.ToString() << std::endl;
|
||||
parms = parms | lepWRONGTYPE;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
|
||||
parms = parms | lepOKAY;
|
||||
std::cerr << "getASNode<" << nodeID.ToString() << std::endl;
|
||||
|
||||
return sle;
|
||||
|
||||
@@ -90,17 +82,7 @@ SerializedLedgerEntry::pointer Ledger::getAccountRoot(LedgerStateParms& parms, c
|
||||
{
|
||||
uint256 nodeID=getAccountRootIndex(accountID);
|
||||
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
try
|
||||
{
|
||||
return getASNode(parms, nodeID, ltACCOUNT_ROOT);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
parms = lepERROR;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
return getASNode(parms, nodeID, ltACCOUNT_ROOT);
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID)
|
||||
@@ -117,15 +99,7 @@ SerializedLedgerEntry::pointer Ledger::getNickname(LedgerStateParms& parms, cons
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
try
|
||||
{
|
||||
return getASNode(parms, nickHash, ltNICKNAME);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
parms = lepERROR;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
return getASNode(parms, nickHash, ltNICKNAME);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -157,15 +131,7 @@ SerializedLedgerEntry::pointer Ledger::getRippleState(LedgerStateParms& parms, c
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
try
|
||||
{
|
||||
return getASNode(parms, uNode, ltRIPPLE_STATE);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
parms = lepERROR;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
return getASNode(parms, uNode, ltRIPPLE_STATE);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -200,32 +166,14 @@ SerializedLedgerEntry::pointer Ledger::getDirRoot(LedgerStateParms& parms, const
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
try
|
||||
{
|
||||
return getASNode(parms, uRootIndex, ltDIR_ROOT);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
parms = lepERROR;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
return getASNode(parms, uRootIndex, ltDIR_ROOT);
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
std::cerr << "getDirNode: " << uNodeIndex.ToString() << std::endl;
|
||||
try
|
||||
{
|
||||
return getASNode(parms, uNodeIndex, ltDIR_NODE);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "getDirNode: ERROR: " << uNodeIndex.ToString() << std::endl;
|
||||
parms = lepERROR;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
}
|
||||
return getASNode(parms, uNodeIndex, ltDIR_NODE);
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -382,19 +382,17 @@ Json::Value RPCServer::doAccountLines(Json::Value ¶ms)
|
||||
AccountState::pointer as = mNetOps->getAccountState(uLedger, naAccount);
|
||||
if (as)
|
||||
{
|
||||
Json::Value jsonLines = Json::Value(Json::objectValue);
|
||||
|
||||
ret["account"] = naAccount.humanAccountID();
|
||||
|
||||
// We access a committed ledger and need not worry about changes.
|
||||
uint256 uDirLineNodeFirst;
|
||||
uint256 uDirLineNodeLast;
|
||||
// Ledger::getDirIndex(uBase, letKind, uNodeDir)
|
||||
|
||||
if (!mNetOps->getDirLineInfo(uLedger, naAccount, uDirLineNodeFirst, uDirLineNodeLast))
|
||||
if (mNetOps->getDirLineInfo(uLedger, naAccount, uDirLineNodeFirst, uDirLineNodeLast))
|
||||
{
|
||||
ret["lines"] = Json::Value(Json::objectValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Json::Value jsonLines = Json::Value(Json::objectValue);
|
||||
|
||||
for (; uDirLineNodeFirst <= uDirLineNodeLast; uDirLineNodeFirst++)
|
||||
{
|
||||
@@ -409,27 +407,35 @@ Json::Value RPCServer::doAccountLines(Json::Value ¶ms)
|
||||
|
||||
RippleState::pointer rsLine = mNetOps->getRippleState(uLedger, uNode);
|
||||
|
||||
rsLine->setViewAccount(naAccount);
|
||||
if (rsLine)
|
||||
{
|
||||
rsLine->setViewAccount(naAccount);
|
||||
|
||||
naAccountPeer = rsLine->getAccountIDPeer();
|
||||
saBalance = rsLine->getBalance();
|
||||
saLimit = rsLine->getLimit();
|
||||
saLimitPeer = rsLine->getLimitPeer();
|
||||
naAccountPeer = rsLine->getAccountIDPeer();
|
||||
saBalance = rsLine->getBalance();
|
||||
saLimit = rsLine->getLimit();
|
||||
saLimitPeer = rsLine->getLimitPeer();
|
||||
|
||||
Json::Value jPeer = Json::Value(Json::objectValue);
|
||||
Json::Value jPeer = Json::Value(Json::objectValue);
|
||||
|
||||
jPeer["balance"] = saBalance.getText();
|
||||
jPeer["currency"] = saBalance.getCurrencyHuman();
|
||||
jPeer["limit"] = saLimit.getJson(0);
|
||||
jPeer["limit_peer"] = saLimitPeer.getJson(0);
|
||||
jPeer["node"] = uNode.ToString();
|
||||
|
||||
ret[naAccountPeer.humanAccountID()] = jPeer;
|
||||
jPeer["balance"] = saBalance.getText();
|
||||
jPeer["currency"] = saBalance.getCurrencyHuman();
|
||||
jPeer["limit"] = saLimit.getJson(0);
|
||||
jPeer["limit_peer"] = saLimitPeer.getJson(0);
|
||||
|
||||
jsonLines[naAccountPeer.humanAccountID()] = jPeer;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "doAccountLines: Bad index: " << uNode.ToString() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret["lines"] = jsonLines;
|
||||
|
||||
}
|
||||
ret["lines"] = jsonLines;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -13,6 +13,8 @@ RippleState::RippleState(SerializedLedgerEntry::pointer ledgerEntry) :
|
||||
mLowLimit = mLedgerEntry->getIValueFieldAmount(sfLowLimit);
|
||||
mHighLimit = mLedgerEntry->getIValueFieldAmount(sfHighLimit);
|
||||
|
||||
mBalance = mLedgerEntry->getIValueFieldAmount(sfBalance);
|
||||
|
||||
// YYY Should never fail.
|
||||
if (mLowID.isValid() && mHighID.isValid())
|
||||
mValid = true;
|
||||
|
||||
23
src/SHAMap.h
23
src/SHAMap.h
@@ -80,9 +80,14 @@ class hash_SMN
|
||||
{ // These must be randomized for release
|
||||
public:
|
||||
std::size_t operator() (const SHAMapNode& mn) const
|
||||
#if 0
|
||||
{ return mn.getDepth() ^ static_cast<std::size_t>(mn.getNodeID().GetAt(0)); }
|
||||
#else
|
||||
{ return mn.getDepth() ^ *reinterpret_cast<const std::size_t *>(mn.getNodeID().begin()); }
|
||||
#endif
|
||||
|
||||
std::size_t operator() (const uint256& u) const
|
||||
{ return static_cast<std::size_t>(u.GetAt(0)); }
|
||||
{ return *reinterpret_cast<const std::size_t *>(u.begin()); }
|
||||
};
|
||||
|
||||
class SHAMapItem
|
||||
@@ -109,18 +114,22 @@ public:
|
||||
|
||||
void updateData(const std::vector<unsigned char>& data) { mData=data; }
|
||||
|
||||
bool operator<(const SHAMapItem& i) const { return mTag < i.mTag; }
|
||||
bool operator>(const SHAMapItem& i) const { return mTag > i.mTag; }
|
||||
bool operator==(const SHAMapItem& i) const { return mTag == i.mTag; }
|
||||
bool operator!=(const SHAMapItem& i) const { return mTag != i.mTag; }
|
||||
bool operator<=(const SHAMapItem& i) const { return mTag <= i.mTag; }
|
||||
bool operator>=(const SHAMapItem& i) const { return mTag >= i.mTag; }
|
||||
bool operator<(const uint256& i) const { return mTag < i; }
|
||||
bool operator>(const uint256& i) const { return mTag > i; }
|
||||
bool operator==(const uint256& i) const { return mTag == i; }
|
||||
bool operator!=(const uint256& i) const { return mTag != i; }
|
||||
#if 0
|
||||
// This code is comment out because it is unused. It could work.
|
||||
bool operator<(const SHAMapItem& i) const { return mTag < i.mTag; }
|
||||
bool operator>(const SHAMapItem& i) const { return mTag > i.mTag; }
|
||||
bool operator<=(const SHAMapItem& i) const { return mTag <= i.mTag; }
|
||||
bool operator>=(const SHAMapItem& i) const { return mTag >= i.mTag; }
|
||||
|
||||
bool operator<(const uint256& i) const { return mTag < i; }
|
||||
bool operator>(const uint256& i) const { return mTag > i; }
|
||||
bool operator<=(const uint256& i) const { return mTag <= i; }
|
||||
bool operator>=(const uint256& i) const { return mTag >= i; }
|
||||
#endif
|
||||
virtual void dump();
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
@@ -13,12 +14,9 @@
|
||||
|
||||
std::string SHAMapNode::getString() const
|
||||
{
|
||||
std::string ret="NodeID(";
|
||||
ret+=boost::lexical_cast<std::string>(mDepth);
|
||||
ret+=",";
|
||||
ret+=mNodeID.GetHex();
|
||||
ret+=")";
|
||||
return ret;
|
||||
return str(boost::format("NodeID(%s,%s)")
|
||||
% boost::lexical_cast<std::string>(mDepth)
|
||||
% mNodeID.GetHex());
|
||||
}
|
||||
|
||||
uint256 SHAMapNode::smMasks[64];
|
||||
@@ -77,7 +75,7 @@ void SHAMapNode::ClassInit()
|
||||
for(int i = 0; i < 64; i += 2)
|
||||
{
|
||||
smMasks[i] = selector;
|
||||
*(selector.begin() + (i / 2)) = 0x0F;
|
||||
*(selector.begin() + (i / 2)) = 0xF0;
|
||||
smMasks[i + 1]=selector;
|
||||
*(selector.begin() + (i / 2)) = 0xFF;
|
||||
}
|
||||
@@ -123,13 +121,14 @@ SHAMapNode SHAMapNode::getChildNodeID(int m) const
|
||||
assert((m >= 0) && (m < 16));
|
||||
|
||||
uint256 child(mNodeID);
|
||||
child.PeekAt(mDepth / 8) |= m << (4 * (mDepth % 8));
|
||||
|
||||
child.begin()[mDepth/2] |= (mDepth & 1) ? m : m << 4;
|
||||
|
||||
return SHAMapNode(mDepth + 1, child);
|
||||
}
|
||||
|
||||
int SHAMapNode::selectBranch(const uint256& hash) const
|
||||
{ // Which branch would contain the specified hash
|
||||
|
||||
#ifdef DEBUG
|
||||
if (mDepth == 63)
|
||||
{
|
||||
@@ -147,8 +146,10 @@ int SHAMapNode::selectBranch(const uint256& hash) const
|
||||
#endif
|
||||
|
||||
int branch = *(hash.begin() + (mDepth / 2));
|
||||
if (mDepth % 2) branch >>= 4;
|
||||
else branch &= 0xf;
|
||||
if (mDepth & 1)
|
||||
branch &= 0xf;
|
||||
else
|
||||
branch >>= 4;
|
||||
|
||||
assert((branch >= 0) && (branch < 16));
|
||||
return branch;
|
||||
@@ -259,6 +260,7 @@ void SHAMapTreeNode::addRaw(Serializer &s)
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
s.add256(mHashes[i]);
|
||||
|
||||
s.add8(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,10 +186,20 @@ STVector256* STVector256::construct(SerializerIterator& u, const char *name)
|
||||
{
|
||||
std::vector<unsigned char> data = u.getVL();
|
||||
std::vector<uint256> value;
|
||||
|
||||
int count = data.size() / (256 / 8);
|
||||
value.reserve(count);
|
||||
for(int i = 0; i < count; i++)
|
||||
value.push_back(uint256(std::vector<unsigned char>(&data[i], &data[i + (256 / 8)])));
|
||||
|
||||
unsigned int uStart = 0;
|
||||
for (unsigned int i = 0; i != count; i++)
|
||||
{
|
||||
unsigned int uEnd = uStart+(256/8);
|
||||
|
||||
value.push_back(uint256(std::vector<unsigned char>(&data[uStart], &data[uEnd])));
|
||||
|
||||
uStart = uEnd;
|
||||
}
|
||||
|
||||
return new STVector256(name, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ public:
|
||||
friend STAmount convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit,
|
||||
const char* name = NULL);
|
||||
|
||||
static STAmount deSerialize(SerializerIterator&);
|
||||
static STAmount deserialize(SerializerIterator&);
|
||||
static bool currencyFromString(uint160& uDstCurrency, const std::string& sCurrency);
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
typedef SerializedLedgerEntry SLE;
|
||||
|
||||
#define DIR_NODE_MAX 32
|
||||
#define DIR_NODE_MAX 1
|
||||
|
||||
// We return the uNodeDir so that on delete we can quickly know where the element is mentioned in the directory.
|
||||
TransactionEngineResult TransactionEngine::dirAdd(
|
||||
@@ -63,6 +63,10 @@ TransactionEngineResult TransactionEngine::dirAdd(
|
||||
{
|
||||
// Last node is not full, append.
|
||||
|
||||
std::cerr << "dirAdd: appending: PREV: " << svIndexes.peekValue()[0].ToString() << std::endl;
|
||||
std::cerr << "dirAdd: appending: Node: " << strHex(uNodeDir) << std::endl;
|
||||
std::cerr << "dirAdd: appending: Entry: " << uLedgerIndex.ToString() << std::endl;
|
||||
|
||||
svIndexes.peekValue().push_back(uLedgerIndex);
|
||||
sleNode->setIFieldV256(sfIndexes, svIndexes);
|
||||
|
||||
|
||||
355
src/uint256.h
355
src/uint256.h
@@ -14,6 +14,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
@@ -33,19 +34,12 @@ class base_uint
|
||||
{
|
||||
protected:
|
||||
enum { WIDTH=BITS/32 };
|
||||
|
||||
// This is really big-endian in byte order.
|
||||
// We use unsigned int for speed.
|
||||
unsigned int pn[WIDTH];
|
||||
|
||||
public:
|
||||
|
||||
BIGNUM *toBN() const
|
||||
{
|
||||
// Convert to big-endian
|
||||
unsigned char *be[WIDTH];
|
||||
|
||||
std::reverse_copy(begin(), end(), be);
|
||||
|
||||
return BN_bin2bn(be, WIDTH, NULL);
|
||||
}
|
||||
|
||||
bool isZero() const
|
||||
{
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
@@ -61,10 +55,7 @@ public:
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
if (pn[i] != 0)
|
||||
return false;
|
||||
return true;
|
||||
return isZero();
|
||||
}
|
||||
|
||||
const base_uint operator~() const
|
||||
@@ -75,22 +66,13 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
const base_uint operator-() const
|
||||
{
|
||||
base_uint ret;
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
ret.pn[i] = ~pn[i];
|
||||
++ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
base_uint& operator=(uint64 b)
|
||||
{
|
||||
pn[0] = (unsigned int)b;
|
||||
pn[1] = (unsigned int)(b >> 32);
|
||||
for (int i = 2; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
zero();
|
||||
|
||||
// Put in least significant bits.
|
||||
((uint64_t *) end())[-1] = htobe64(b);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -115,100 +97,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator^=(uint64 b)
|
||||
{
|
||||
pn[0] ^= (unsigned int)(b & 0xffffffffu);
|
||||
pn[1] ^= (unsigned int)(b >> 32);
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator&=(uint64 b)
|
||||
{
|
||||
pn[0] &= (unsigned int)(b & 0xffffffffu);
|
||||
pn[1] &= (unsigned int)(b >> 32);
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator|=(uint64 b)
|
||||
{
|
||||
pn[0] |= (unsigned int)(b & 0xffffffffu);
|
||||
pn[1] |= (unsigned int)(b >> 32);
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator<<=(unsigned int shift)
|
||||
{
|
||||
base_uint a(*this);
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
int k = shift / 32;
|
||||
shift = shift % 32;
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
{
|
||||
if (i+k+1 < WIDTH && shift != 0)
|
||||
pn[i+k+1] |= (a.pn[i] >> (32-shift));
|
||||
if (i+k < WIDTH)
|
||||
pn[i+k] |= (a.pn[i] << shift);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator>>=(unsigned int shift)
|
||||
{
|
||||
base_uint a(*this);
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
int k = shift / 32;
|
||||
shift = shift % 32;
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
{
|
||||
if (i-k-1 >= 0 && shift != 0)
|
||||
pn[i-k-1] |= (a.pn[i] << (32-shift));
|
||||
if (i-k >= 0)
|
||||
pn[i-k] |= (a.pn[i] >> shift);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator+=(const base_uint& b)
|
||||
{
|
||||
uint64 carry = 0;
|
||||
for (int i = 0; i < WIDTH; i++)
|
||||
{
|
||||
uint64 n = carry + pn[i] + b.pn[i];
|
||||
pn[i] = n & 0xffffffff;
|
||||
carry = n >> 32;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator-=(const base_uint& b)
|
||||
{
|
||||
*this += -b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator+=(uint64 b64)
|
||||
{
|
||||
base_uint b(b64);
|
||||
*this += b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
base_uint& operator-=(uint64 b64)
|
||||
{
|
||||
base_uint b(b64);
|
||||
*this += -b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
base_uint& operator++()
|
||||
{
|
||||
// prefix operator
|
||||
int i = 0;
|
||||
while (++pn[i] == 0 && i < WIDTH-1)
|
||||
i++;
|
||||
|
||||
for (int i = WIDTH-1; ++pn[i] == 0 && i; i--)
|
||||
nothing();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -223,9 +118,10 @@ public:
|
||||
base_uint& operator--()
|
||||
{
|
||||
// prefix operator
|
||||
unsigned i = 0;
|
||||
while (--pn[i] == -1 && i < WIDTH-1)
|
||||
i++;
|
||||
|
||||
for (int i = WIDTH-1; --pn[i] == (unsigned int) -1 && i; i--)
|
||||
nothing();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -237,53 +133,36 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
friend inline int compare(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
const unsigned char* pA = a.begin();
|
||||
const unsigned char* pAEnd = a.end();
|
||||
const unsigned char* pB = b.begin();
|
||||
|
||||
while (pA != pAEnd && *pA == *pB)
|
||||
pA++, pB++;
|
||||
|
||||
return pA == pAEnd ? 0 : *pA < *pB ? -1 : *pA > *pB ? 1 : 0;
|
||||
}
|
||||
|
||||
friend inline bool operator<(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
for (int i = base_uint::WIDTH-1; i >= 0; i--)
|
||||
{
|
||||
if (a.pn[i] < b.pn[i])
|
||||
return true;
|
||||
else if (a.pn[i] > b.pn[i])
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return compare(a, b) < 0;
|
||||
}
|
||||
|
||||
friend inline bool operator<=(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
for (int i = base_uint::WIDTH-1; i >= 0; i--)
|
||||
{
|
||||
if (a.pn[i] < b.pn[i])
|
||||
return true;
|
||||
else if (a.pn[i] > b.pn[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return compare(a, b) <= 0;
|
||||
}
|
||||
|
||||
friend inline bool operator>(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
for (int i = base_uint::WIDTH-1; i >= 0; i--)
|
||||
{
|
||||
if (a.pn[i] > b.pn[i])
|
||||
return true;
|
||||
else if (a.pn[i] < b.pn[i])
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return compare(a, b) > 0;
|
||||
}
|
||||
|
||||
friend inline bool operator>=(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
for (int i = base_uint::WIDTH-1; i >= 0; i--)
|
||||
{
|
||||
if (a.pn[i] > b.pn[i])
|
||||
return true;
|
||||
else if (a.pn[i] < b.pn[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return compare(a, b) >= 0;
|
||||
}
|
||||
|
||||
friend inline bool operator==(const base_uint& a, const base_uint& b)
|
||||
@@ -294,44 +173,14 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
friend inline bool operator==(const base_uint& a, uint64 b)
|
||||
{
|
||||
if (a.pn[0] != (unsigned int)(b & 0xffffffffu))
|
||||
return false;
|
||||
if (a.pn[1] != (unsigned int)(b >> 32))
|
||||
return false;
|
||||
for (int i = 2; i < base_uint::WIDTH; i++)
|
||||
if (a.pn[i] != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
friend inline bool operator!=(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
return (!(a == b));
|
||||
}
|
||||
|
||||
friend inline bool operator!=(const base_uint& a, uint64 b)
|
||||
{
|
||||
return (!(a == b));
|
||||
}
|
||||
|
||||
unsigned int GetAt(int j) const
|
||||
{
|
||||
return pn[j];
|
||||
}
|
||||
|
||||
unsigned int& PeekAt(int j)
|
||||
{
|
||||
return pn[j];
|
||||
}
|
||||
|
||||
std::string GetHex() const
|
||||
{
|
||||
char psz[sizeof(pn)*2 + 1];
|
||||
for (int i = 0; i < sizeof(pn); i++)
|
||||
sprintf(psz + i*2, "%02X", ((unsigned char*)pn)[sizeof(pn) - i - 1]);
|
||||
return std::string(psz, psz + sizeof(pn)*2);
|
||||
return strHex(begin(), size());
|
||||
}
|
||||
|
||||
void SetHex(const char* psz)
|
||||
@@ -353,20 +202,23 @@ public:
|
||||
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
|
||||
|
||||
const char* pbegin = psz;
|
||||
const char* pBegin = psz;
|
||||
while (phexdigit[(int) *psz] || *psz == '0')
|
||||
psz++;
|
||||
psz--;
|
||||
unsigned char* p1 = (unsigned char*)pn;
|
||||
unsigned char* pend = p1 + WIDTH * 4;
|
||||
while (psz >= pbegin && p1 < pend)
|
||||
|
||||
unsigned char* pOut = begin();
|
||||
|
||||
if (psz-pBegin > 2*size())
|
||||
psz = pBegin + 2*size();
|
||||
|
||||
while (pBegin != psz)
|
||||
{
|
||||
*p1 = phexdigit[(unsigned char)*psz--];
|
||||
if (psz >= pbegin)
|
||||
{
|
||||
*p1 |= (phexdigit[(unsigned char)*psz--] << 4);
|
||||
p1++;
|
||||
}
|
||||
unsigned char cHigh = phexdigit[(unsigned char) *pBegin++] << 4;
|
||||
unsigned char cLow = pBegin == psz
|
||||
? 0
|
||||
: phexdigit[(unsigned char) *pBegin++];
|
||||
*pOut++ = cHigh | cLow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,22 +234,22 @@ public:
|
||||
|
||||
unsigned char* begin()
|
||||
{
|
||||
return (unsigned char*)&pn[0];
|
||||
return (unsigned char*) &pn[0];
|
||||
}
|
||||
|
||||
unsigned char* end()
|
||||
{
|
||||
return (unsigned char*)&pn[WIDTH];
|
||||
return (unsigned char*) &pn[WIDTH];
|
||||
}
|
||||
|
||||
const unsigned char* begin() const
|
||||
{
|
||||
return (const unsigned char*)&pn[0];
|
||||
return (const unsigned char*) &pn[0];
|
||||
}
|
||||
|
||||
const unsigned char* end() const
|
||||
{
|
||||
return (unsigned char*)&pn[WIDTH];
|
||||
return (unsigned char*) &pn[WIDTH];
|
||||
}
|
||||
|
||||
unsigned int size() const
|
||||
@@ -427,7 +279,6 @@ public:
|
||||
s.read((char*)pn, sizeof(pn));
|
||||
}
|
||||
|
||||
|
||||
friend class uint128;
|
||||
friend class uint160;
|
||||
friend class uint256;
|
||||
@@ -518,18 +369,16 @@ public:
|
||||
|
||||
uint160(uint64 b)
|
||||
{
|
||||
pn[0] = (unsigned int)(b & 0xffffffffu);
|
||||
pn[1] = (unsigned int)(b >> 32);
|
||||
for (int i = 2; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
uint160& operator=(uint64 b)
|
||||
{
|
||||
pn[0] = (unsigned int)(b & 0xffffffffu);
|
||||
pn[1] = (unsigned int)(b >> 32);
|
||||
for (int i = 2; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
zero();
|
||||
|
||||
// Put in least significant bits.
|
||||
((uint64_t *) end())[-1] = htobe64(b);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -543,7 +392,7 @@ public:
|
||||
if (vch.size() == sizeof(pn))
|
||||
memcpy(pn, &vch[0], sizeof(pn));
|
||||
else
|
||||
*this = 0;
|
||||
zero();
|
||||
}
|
||||
|
||||
base_uint256 to256() const;
|
||||
@@ -551,52 +400,32 @@ public:
|
||||
|
||||
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, unsigned int shift) { return uint160(a) <<= shift; }
|
||||
inline const uint160 operator>>(const base_uint160& a, unsigned int shift) { return uint160(a) >>= shift; }
|
||||
inline const uint160 operator<<(const uint160& a, unsigned int shift) { return uint160(a) <<= shift; }
|
||||
inline const uint160 operator>>(const uint160& a, unsigned int shift) { return uint160(a) >>= shift; }
|
||||
|
||||
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 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 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 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 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 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 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 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 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 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; }
|
||||
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 std::string strHex(const uint160& ui)
|
||||
{
|
||||
return strHex(ui.begin(), ui.size());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -629,18 +458,16 @@ public:
|
||||
|
||||
uint256(uint64 b)
|
||||
{
|
||||
pn[0] = (unsigned int)(b & 0xffffffff);
|
||||
pn[1] = (unsigned int)(b >> 32);
|
||||
for (int i = 2; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
*this = b;
|
||||
}
|
||||
|
||||
uint256& operator=(uint64 b)
|
||||
{
|
||||
pn[0] = (unsigned int)(b & 0xffffffff);
|
||||
pn[1] = (unsigned int)(b >> 32);
|
||||
for (int i = 2; i < WIDTH; i++)
|
||||
pn[i] = 0;
|
||||
zero();
|
||||
|
||||
// Put in least significant bits.
|
||||
((uint64_t *) end())[-1] = htobe64(b);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -656,7 +483,7 @@ public:
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
*this = 0;
|
||||
zero();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,52 +493,24 @@ public:
|
||||
|
||||
inline bool operator==(const uint256& a, uint64 b) { return (base_uint256)a == b; }
|
||||
inline bool operator!=(const uint256& a, uint64 b) { return (base_uint256)a != b; }
|
||||
inline const uint256 operator<<(const base_uint256& a, unsigned int shift) { return uint256(a) <<= shift; }
|
||||
inline const uint256 operator>>(const base_uint256& a, unsigned int shift) { return uint256(a) >>= shift; }
|
||||
inline const uint256 operator<<(const uint256& a, unsigned int shift) { return uint256(a) <<= shift; }
|
||||
inline const uint256 operator>>(const uint256& a, unsigned int shift) { return uint256(a) >>= shift; }
|
||||
|
||||
inline const uint256 operator^(const base_uint256& a, const base_uint256& b) { return uint256(a) ^= b; }
|
||||
inline const uint256 operator&(const base_uint256& a, const base_uint256& b) { return uint256(a) &= b; }
|
||||
inline const uint256 operator|(const base_uint256& a, const base_uint256& b) { return uint256(a) |= b; }
|
||||
inline const uint256 operator+(const base_uint256& a, const base_uint256& b) { return uint256(a) += b; }
|
||||
inline const uint256 operator-(const base_uint256& a, const base_uint256& b) { return uint256(a) -= b; }
|
||||
|
||||
inline bool operator<(const base_uint256& a, const uint256& b) { return (base_uint256)a < (base_uint256)b; }
|
||||
inline bool operator<=(const base_uint256& a, const uint256& b) { return (base_uint256)a <= (base_uint256)b; }
|
||||
inline bool operator>(const base_uint256& a, const uint256& b) { return (base_uint256)a > (base_uint256)b; }
|
||||
inline bool operator>=(const base_uint256& a, const uint256& b) { return (base_uint256)a >= (base_uint256)b; }
|
||||
inline bool operator==(const base_uint256& a, const uint256& b) { return (base_uint256)a == (base_uint256)b; }
|
||||
inline bool operator!=(const base_uint256& a, const uint256& b) { return (base_uint256)a != (base_uint256)b; }
|
||||
inline const uint256 operator^(const base_uint256& a, const uint256& b) { return (base_uint256)a ^ (base_uint256)b; }
|
||||
inline const uint256 operator&(const base_uint256& a, const uint256& b) { return (base_uint256)a & (base_uint256)b; }
|
||||
inline const uint256 operator|(const base_uint256& a, const uint256& b) { return (base_uint256)a | (base_uint256)b; }
|
||||
inline const uint256 operator+(const base_uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; }
|
||||
inline const uint256 operator-(const base_uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; }
|
||||
|
||||
inline bool operator<(const uint256& a, const base_uint256& b) { return (base_uint256)a < (base_uint256)b; }
|
||||
inline bool operator<=(const uint256& a, const base_uint256& b) { return (base_uint256)a <= (base_uint256)b; }
|
||||
inline bool operator>(const uint256& a, const base_uint256& b) { return (base_uint256)a > (base_uint256)b; }
|
||||
inline bool operator>=(const uint256& a, const base_uint256& b) { return (base_uint256)a >= (base_uint256)b; }
|
||||
inline bool operator==(const uint256& a, const base_uint256& b) { return (base_uint256)a == (base_uint256)b; }
|
||||
inline bool operator!=(const uint256& a, const base_uint256& b) { return (base_uint256)a != (base_uint256)b; }
|
||||
inline const uint256 operator^(const uint256& a, const base_uint256& b) { return (base_uint256)a ^ (base_uint256)b; }
|
||||
inline const uint256 operator&(const uint256& a, const base_uint256& b) { return (base_uint256)a & (base_uint256)b; }
|
||||
inline const uint256 operator|(const uint256& a, const base_uint256& b) { return (base_uint256)a | (base_uint256)b; }
|
||||
inline const uint256 operator+(const uint256& a, const base_uint256& b) { return (base_uint256)a + (base_uint256)b; }
|
||||
inline const uint256 operator-(const uint256& a, const base_uint256& b) { return (base_uint256)a - (base_uint256)b; }
|
||||
|
||||
inline bool operator<(const uint256& a, const uint256& b) { return (base_uint256)a < (base_uint256)b; }
|
||||
inline bool operator<=(const uint256& a, const uint256& b) { return (base_uint256)a <= (base_uint256)b; }
|
||||
inline bool operator>(const uint256& a, const uint256& b) { return (base_uint256)a > (base_uint256)b; }
|
||||
inline bool operator>=(const uint256& a, const uint256& b) { return (base_uint256)a >= (base_uint256)b; }
|
||||
inline bool operator==(const uint256& a, const uint256& b) { return (base_uint256)a == (base_uint256)b; }
|
||||
inline bool 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; }
|
||||
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; }
|
||||
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; }
|
||||
|
||||
uint256 uint160extend256(const uint160& uSource, uint uNamespace);
|
||||
|
||||
@@ -719,7 +518,6 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
|
||||
{
|
||||
uint256 g(0);
|
||||
|
||||
|
||||
printf("%s\n", g.ToString().c_str());
|
||||
--g; printf("--g\n");
|
||||
printf("%s\n", g.ToString().c_str());
|
||||
@@ -754,11 +552,11 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
|
||||
a.pn[3] = 15;
|
||||
printf("%s\n", a.ToString().c_str());
|
||||
b = 1;
|
||||
b <<= 52;
|
||||
// b <<= 52;
|
||||
|
||||
a |= b;
|
||||
|
||||
a ^= 0x500;
|
||||
// a ^= 0x500;
|
||||
|
||||
printf("a %s\n", a.ToString().c_str());
|
||||
|
||||
@@ -816,7 +614,7 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
|
||||
printf("%s\n", x1.ToString().c_str());
|
||||
for (int i = 0; i < 270; i += 4)
|
||||
{
|
||||
x2 = x1 << i;
|
||||
// x2 = x1 << i;
|
||||
printf("%s\n", x2.ToString().c_str());
|
||||
}
|
||||
|
||||
@@ -825,11 +623,11 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
|
||||
for (int i = 0; i < 270; i += 4)
|
||||
{
|
||||
x2 = x1;
|
||||
x2 >>= i;
|
||||
// x2 >>= i;
|
||||
printf("%s\n", x2.ToString().c_str());
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
uint256 k = (~uint256(0) >> i);
|
||||
@@ -841,6 +639,7 @@ inline int Testuint256AdHoc(std::vector<std::string> vArg)
|
||||
uint256 k = (~uint256(0) << i);
|
||||
printf("%s\n", k.ToString().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
#include <openssl/dh.h>
|
||||
|
||||
#include "uint256.h"
|
||||
#include "types.h"
|
||||
// #include "uint256.h"
|
||||
|
||||
#define nothing() do {} while (0)
|
||||
|
||||
@@ -64,9 +65,11 @@ inline std::string strHex(const std::vector<unsigned char>& vucData)
|
||||
return strHex(vucData.begin(), vucData.size());
|
||||
}
|
||||
|
||||
inline const std::string strHex(const uint160& ui)
|
||||
inline std::string strHex(const uint64 uiHost)
|
||||
{
|
||||
return strHex(ui.begin(), ui.size());
|
||||
uint64_t uBig = htobe64(uiHost);
|
||||
|
||||
return strHex((unsigned char*) &uBig, sizeof(uBig));
|
||||
}
|
||||
|
||||
template<class Iterator>
|
||||
|
||||
Reference in New Issue
Block a user