mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Various cleanups, mostly style and whitespace.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
@@ -19,9 +18,7 @@
|
||||
#include "Config.h"
|
||||
#include "BitcoinUtil.h"
|
||||
|
||||
using namespace boost::asio;
|
||||
|
||||
inline bool isSwitchChar(char c)
|
||||
static inline bool isSwitchChar(char c)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
return c == '-' || c == '/';
|
||||
@@ -56,13 +53,13 @@ int commandLineRPC(int argc, char *argv[])
|
||||
try
|
||||
{
|
||||
// Skip switches
|
||||
while(argc > 1 && isSwitchChar(argv[1][0]))
|
||||
while ((argc > 1) && isSwitchChar(argv[1][0]))
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if(argc < 2) return(0);
|
||||
if (argc < 2) return 0;
|
||||
|
||||
std::string strMethod = argv[1];
|
||||
|
||||
@@ -78,19 +75,17 @@ int commandLineRPC(int argc, char *argv[])
|
||||
Json::Value result = reply.get("result", Json::Value());
|
||||
Json::Value error = reply.get("error", Json::Value());
|
||||
|
||||
if(result.isString() && result.asString()=="unknown command")
|
||||
if (result.isString() && (result.asString() == "unknown command"))
|
||||
nRet=1;
|
||||
|
||||
if (!error.isNull())
|
||||
{
|
||||
// Error
|
||||
{ // Error
|
||||
strPrint = "error: " + error.toStyledString();
|
||||
int code = error["code"].asInt();
|
||||
nRet = abs(code);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Result
|
||||
{ // Result
|
||||
if (result.isNull())
|
||||
strPrint = "";
|
||||
else if (result.isString())
|
||||
@@ -119,27 +114,24 @@ int commandLineRPC(int argc, char *argv[])
|
||||
|
||||
Json::Value callRPC(const std::string& strMethod, const Json::Value& params)
|
||||
{
|
||||
if(theConfig.RPC_USER == "" && theConfig.RPC_PASSWORD == "")
|
||||
if (theConfig.RPC_USER.empty() && theConfig.RPC_PASSWORD.empty())
|
||||
throw std::runtime_error("You must set rpcpassword=<password> in the configuration file"
|
||||
"If the file does not exist, create it with owner-readable-only file permissions.");
|
||||
|
||||
// Connect to localhost
|
||||
|
||||
std::cout << "Connecting to port:" << theConfig.RPC_PORT << std::endl;
|
||||
ip::tcp::endpoint endpoint(ip::address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT);
|
||||
ip::tcp::iostream stream;
|
||||
boost::asio::ip::tcp::endpoint
|
||||
endpoint(boost::asio::ip::address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT);
|
||||
boost::asio::ip::tcp::iostream stream;
|
||||
stream.connect(endpoint);
|
||||
if (stream.fail())
|
||||
throw std::runtime_error("couldn't connect to server");
|
||||
|
||||
|
||||
|
||||
// HTTP basic authentication
|
||||
std::string strUserPass64 = EncodeBase64(theConfig.RPC_USER + ":" + theConfig.RPC_PASSWORD);
|
||||
std::map<std::string, std::string> mapRequestHeaders;
|
||||
mapRequestHeaders["Authorization"] = std::string("Basic ") + strUserPass64;
|
||||
|
||||
|
||||
// Send request
|
||||
std::string strRequest = JSONRPCRequest(strMethod, params, Json::Value(1));
|
||||
std::cout << "send request " << strMethod << " : " << strRequest << std::endl;
|
||||
@@ -154,7 +146,7 @@ Json::Value callRPC(const std::string& strMethod, const Json::Value& params)
|
||||
int nStatus = ReadHTTP(stream, mapHeaders, strReply);
|
||||
if (nStatus == 401)
|
||||
throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
|
||||
else if (nStatus >= 400 && nStatus != 400 && nStatus != 404 && nStatus != 500)
|
||||
else if ((nStatus >= 400) && (nStatus != 400) && (nStatus != 404) && (nStatus != 500)) // ?
|
||||
throw std::runtime_error(strprintf("server returned HTTP error %d", nStatus));
|
||||
else if (strReply.empty())
|
||||
throw std::runtime_error("no response from server");
|
||||
@@ -170,3 +162,4 @@ Json::Value callRPC(const std::string& strMethod, const Json::Value& params)
|
||||
return valReply;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -138,8 +138,8 @@ uint64 Ledger::getBalance(const NewcoinAddress& accountID) const
|
||||
bool Ledger::updateAccountState(AccountState::pointer state)
|
||||
{
|
||||
assert(!mAccepted);
|
||||
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID().getAccountID(), state->getRaw());
|
||||
return mAccountStateMap->updateGiveItem(item, false);
|
||||
return mAccountStateMap->updateGiveItem(boost::make_shared<SHAMapItem>(state->getAccountID().getAccountID(),
|
||||
state->getRaw()), false);
|
||||
}
|
||||
|
||||
bool Ledger::addAccountState(AccountState::pointer state)
|
||||
@@ -180,7 +180,8 @@ Transaction::pointer Ledger::getTransaction(const uint256& transID) const
|
||||
if (txn) return txn;
|
||||
|
||||
txn = boost::make_shared<Transaction>(item->getData(), true);
|
||||
if(txn->getStatus()==NEW) txn->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
||||
if (txn->getStatus() == NEW)
|
||||
txn->setStatus(mClosed ? COMMITTED : INCLUDED, mLedgerSeq);
|
||||
|
||||
theApp->getMasterTransaction().canonicalize(txn, false);
|
||||
return txn;
|
||||
@@ -537,8 +538,7 @@ Ledger::pointer Ledger::switchPreviousLedger(Ledger::pointer oldPrevious, Ledger
|
||||
// 5) Try to add transactions from this ledger to the new ledger.
|
||||
std::map<uint256, Transaction::pointer> txnMap;
|
||||
for(SHAMapItem::pointer mit = peekTransactionMap()->peekFirstItem();
|
||||
!!mit;
|
||||
mit=peekTransactionMap()->peekNextItem(mit->getTag()))
|
||||
!!mit; mit = peekTransactionMap()->peekNextItem(mit->getTag()))
|
||||
{
|
||||
uint256 txnID = mit->getTag();
|
||||
Transaction::pointer tx = theApp->getMasterTransaction().fetch(txnID, false);
|
||||
|
||||
@@ -79,14 +79,15 @@ STObject::STObject(SOElement* elem, const char *name) : SerializedType(name), mF
|
||||
{
|
||||
while (elem->e_id != STI_DONE)
|
||||
{
|
||||
if(elem->e_type==SOE_FLAGS) mFlagIdx=mType.size();
|
||||
if (elem->e_type == SOE_FLAGS)
|
||||
mFlagIdx = mType.size();
|
||||
mType.push_back(elem);
|
||||
if ( (elem->e_type == SOE_IFFLAG) || (elem->e_type == SOE_IFNFLAG) )
|
||||
giveObject(new STObject(elem->e_name));
|
||||
else
|
||||
{
|
||||
SerializedType* t = makeDefaultObject(elem->e_id, elem->e_name);
|
||||
if(!t) throw(std::runtime_error("invalid transaction element"));
|
||||
if (!t) throw std::runtime_error("invalid transaction element");
|
||||
giveObject(t);
|
||||
}
|
||||
elem++;
|
||||
@@ -120,7 +121,7 @@ STObject::STObject(SOElement* elem, SerializerIterator& sit, const char *name) :
|
||||
if(!done)
|
||||
{
|
||||
SerializedType* t = makeDeserializedObject(elem->e_id, elem->e_name, sit);
|
||||
if(!t) throw(std::runtime_error("invalid transaction element"));
|
||||
if (!t) throw std::runtime_error("invalid transaction element");
|
||||
giveObject(t);
|
||||
}
|
||||
elem++;
|
||||
@@ -383,7 +384,7 @@ void STObject::setValueFieldU8(SOE_Field field, unsigned char v)
|
||||
id = rf->getSType();
|
||||
}
|
||||
STUInt8* cf = dynamic_cast<STUInt8*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -399,7 +400,7 @@ void STObject::setValueFieldU16(SOE_Field field, uint16 v)
|
||||
id = rf->getSType();
|
||||
}
|
||||
STUInt16* cf = dynamic_cast<STUInt16*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -415,7 +416,7 @@ void STObject::setValueFieldU32(SOE_Field field, uint32 v)
|
||||
id = rf->getSType();
|
||||
}
|
||||
STUInt32* cf = dynamic_cast<STUInt32*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -431,7 +432,7 @@ void STObject::setValueFieldU64(SOE_Field field, uint64 v)
|
||||
id = rf->getSType();
|
||||
}
|
||||
STUInt64* cf = dynamic_cast<STUInt64*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -447,7 +448,7 @@ void STObject::setValueFieldH160(SOE_Field field, const uint160& v)
|
||||
id = rf->getSType();
|
||||
}
|
||||
STHash160* cf = dynamic_cast<STHash160*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -463,7 +464,7 @@ void STObject::setValueFieldVL(SOE_Field field, const std::vector<unsigned char>
|
||||
id=rf->getSType();
|
||||
}
|
||||
STVariableLength* cf = dynamic_cast<STVariableLength*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -479,7 +480,7 @@ void STObject::setValueFieldTL(SOE_Field field, const std::vector<TaggedListItem
|
||||
id=rf->getSType();
|
||||
}
|
||||
STTaggedList* cf = dynamic_cast<STTaggedList*>(rf);
|
||||
if(!cf) throw(std::runtime_error("Wrong field type"));
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
cf->setValue(v);
|
||||
}
|
||||
|
||||
@@ -487,7 +488,8 @@ Json::Value STObject::getJson(int options) const
|
||||
{
|
||||
Json::Value ret(Json::objectValue);
|
||||
int index = 1;
|
||||
for(boost::ptr_vector<SerializedType>::const_iterator it=mData.begin(), end=mData.end(); it!=end; ++it, ++index)
|
||||
for(boost::ptr_vector<SerializedType>::const_iterator it = mData.begin(), end = mData.end(); it != end;
|
||||
++it, ++index)
|
||||
{
|
||||
if (it->getSType() != STI_NOTPRESENT)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,11 @@
|
||||
|
||||
enum SOE_Type
|
||||
{
|
||||
SOE_NEVER=-1, SOE_REQUIRED=0, SOE_FLAGS, SOE_IFFLAG=1, SOE_IFNFLAG=2
|
||||
SOE_NEVER = -1, // never occurs (marks end of object)
|
||||
SOE_REQUIRED = 0, // required
|
||||
SOE_FLAGS = 1, // flags field
|
||||
SOE_IFFLAG = 2, // present if flag set
|
||||
SOE_IFNFLAG = 3 // present if flag not set
|
||||
};
|
||||
|
||||
enum SOE_Field
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
SerializedTransaction::SerializedTransaction(TransactionType type)
|
||||
{
|
||||
mFormat=getTxnFormat(type);
|
||||
if(mFormat==NULL) throw(std::runtime_error("invalid transaction type"));
|
||||
if (mFormat == NULL) throw std::runtime_error("invalid transaction type");
|
||||
|
||||
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
||||
mMiddleTxn.giveObject(new STVariableLength("SigningAccount"));
|
||||
@@ -20,12 +20,12 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length
|
||||
if (length == -1) length=sit.getBytesLeft();
|
||||
else if (length == 0) length=sit.get32();
|
||||
if ( (length < TransactionMinLen) || (length > TransactionMaxLen) )
|
||||
throw(std::runtime_error("Transaction length invalid"));
|
||||
throw std::runtime_error("Transaction length invalid");
|
||||
|
||||
mSignature.setValue(sit.getVL());
|
||||
|
||||
if (sit.get32() != TransactionMagic)
|
||||
throw(std::runtime_error("Transaction has invalid magic"));
|
||||
throw std::runtime_error("Transaction has invalid magic");
|
||||
|
||||
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
||||
mMiddleTxn.giveObject(new STVariableLength("SigningAccount", sit.getVL()));
|
||||
@@ -34,7 +34,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length
|
||||
int type = sit.get32();
|
||||
mMiddleTxn.giveObject(new STUInt32("Type", type));
|
||||
mFormat = getTxnFormat(static_cast<TransactionType>(type));
|
||||
if(!mFormat) throw(std::runtime_error("Transaction has invalid type"));
|
||||
if (!mFormat) throw std::runtime_error("Transaction has invalid type");
|
||||
mMiddleTxn.giveObject(new STUInt64("Fee", sit.get64()));
|
||||
|
||||
mInnerTxn = STObject(mFormat->elements, sit, "InnerTransaction");
|
||||
@@ -132,42 +132,42 @@ void SerializedTransaction::setSignature(const std::vector<unsigned char>& sig)
|
||||
uint32 SerializedTransaction::getVersion() const
|
||||
{
|
||||
const STUInt32* v = dynamic_cast<const STUInt32*>(mMiddleTxn.peekAtPIndex(TransactionIVersion));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->getValue();
|
||||
}
|
||||
|
||||
void SerializedTransaction::setVersion(uint32 ver)
|
||||
{
|
||||
STUInt32* v = dynamic_cast<STUInt32*>(mMiddleTxn.getPIndex(TransactionIVersion));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
v->setValue(ver);
|
||||
}
|
||||
|
||||
uint64 SerializedTransaction::getTransactionFee() const
|
||||
{
|
||||
const STUInt64* v = dynamic_cast<const STUInt64*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->getValue();
|
||||
}
|
||||
|
||||
void SerializedTransaction::setTransactionFee(uint64 fee)
|
||||
{
|
||||
STUInt64* v = dynamic_cast<STUInt64*>(mMiddleTxn.getPIndex(TransactionIFee));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
v->setValue(fee);
|
||||
}
|
||||
|
||||
uint32 SerializedTransaction::getSequence() const
|
||||
{
|
||||
const STUInt32* v = dynamic_cast<const STUInt32*>(mMiddleTxn.peekAtPIndex(TransactionISequence));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->getValue();
|
||||
}
|
||||
|
||||
void SerializedTransaction::setSequence(uint32 seq)
|
||||
{
|
||||
STUInt32* v = dynamic_cast<STUInt32*>(mMiddleTxn.getPIndex(TransactionISequence));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
v->setValue(seq);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ std::vector<unsigned char> SerializedTransaction::getSigningAccount() const
|
||||
{
|
||||
const STVariableLength* v =
|
||||
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->getValue();
|
||||
}
|
||||
|
||||
@@ -183,21 +183,21 @@ const std::vector<unsigned char>& SerializedTransaction::peekSigningAccount() co
|
||||
{
|
||||
const STVariableLength* v=
|
||||
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->peekValue();
|
||||
}
|
||||
|
||||
std::vector<unsigned char>& SerializedTransaction::peekSigningAccount()
|
||||
{
|
||||
STVariableLength* v = dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->peekValue();
|
||||
}
|
||||
|
||||
void SerializedTransaction::setSigningAccount(const std::vector<unsigned char>& s)
|
||||
{
|
||||
STVariableLength* v = dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
v->setValue(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ int Serializer::addRaw(const void *ptr, int len)
|
||||
bool Serializer::get16(uint16& o, int offset) const
|
||||
{
|
||||
if ((offset + 2) > mData.size()) return false;
|
||||
o=mData.at(offset++);
|
||||
o = mData.at(++offset);
|
||||
o <<= 8; o |= mData.at(offset);
|
||||
return true;
|
||||
}
|
||||
@@ -82,8 +82,8 @@ bool Serializer::get16(uint16& o, int offset) const
|
||||
bool Serializer::get32(uint32& o, int offset) const
|
||||
{
|
||||
if ((offset + 4) > mData.size()) return false;
|
||||
o=mData.at(offset++);
|
||||
o<<=8; o|=mData.at(offset++); o<<=8; o|=mData.at(offset++);
|
||||
o=mData.at(++offset);
|
||||
o<<=8; o |= mData.at(++offset); o <<= 8; o |= mData.at(++offset);
|
||||
o<<=8; o |= mData.at(offset);
|
||||
return true;
|
||||
}
|
||||
@@ -91,10 +91,10 @@ bool Serializer::get32(uint32& o, int offset) const
|
||||
bool Serializer::get64(uint64& o, int offset) const
|
||||
{
|
||||
if ((offset + 8) > mData.size()) return false;
|
||||
o=mData.at(offset++);
|
||||
o<<=8; o|=mData.at(offset++); o<<=8; o|=mData.at(offset++);
|
||||
o<<=8; o|=mData.at(offset++); o<<=8; o|=mData.at(offset++);
|
||||
o<<=8; o|=mData.at(offset++); o<<=8; o|=mData.at(offset++);
|
||||
o=mData.at(++offset);
|
||||
o<<=8; o|= mData.at(++offset); o <<= 8; o |= mData.at(++offset);
|
||||
o<<=8; o|= mData.at(++offset); o <<= 8; o |= mData.at(++offset);
|
||||
o<<=8; o|= mData.at(++offset); o <<= 8; o |= mData.at(++offset);
|
||||
o<<=8; o|= mData.at(offset);
|
||||
return true;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ int Serializer::getTaggedListLength(const std::vector<TaggedListItem>& list)
|
||||
bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const
|
||||
{
|
||||
int b1;
|
||||
if(!get8(b1, offset++)) return false;
|
||||
if (!get8(b1, ++offset)) return false;
|
||||
|
||||
int datLen, lenLen = decodeLengthLength(b1);
|
||||
try
|
||||
@@ -325,14 +325,14 @@ bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& le
|
||||
else if (lenLen == 2)
|
||||
{
|
||||
int b2;
|
||||
if(!get8(b2, offset++)) return false;
|
||||
if (!get8(b2, ++offset)) return false;
|
||||
datLen=decodeVLLength(b1, b2);
|
||||
}
|
||||
else if (lenLen == 3)
|
||||
{
|
||||
int b2, b3;
|
||||
if(!get8(b2, offset++)) return false;
|
||||
if(!get8(b3, offset++)) return false;
|
||||
if (!get8(b2, ++offset)) return false;
|
||||
if (!get8(b3, ++offset)) return false;
|
||||
datLen = decodeVLLength(b1, b2, b3);
|
||||
}
|
||||
else return false;
|
||||
@@ -348,7 +348,7 @@ bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& le
|
||||
bool Serializer::getVLLength(int& length, int offset) const
|
||||
{
|
||||
int b1;
|
||||
if(!get8(b1, offset++)) return false;
|
||||
if (!get8(b1, ++offset)) return false;
|
||||
|
||||
int lenLen = decodeLengthLength(b1);
|
||||
try
|
||||
@@ -358,14 +358,14 @@ bool Serializer::getVLLength(int& length, int offset) const
|
||||
else if (lenLen == 2)
|
||||
{
|
||||
int b2;
|
||||
if(!get8(b2, offset++)) return false;
|
||||
if (!get8(b2, ++offset)) return false;
|
||||
length=decodeVLLength(b1, b2);
|
||||
}
|
||||
else if (lenLen == 3)
|
||||
{
|
||||
int b2, b3;
|
||||
if(!get8(b2, offset++)) return false;
|
||||
if(!get8(b3, offset++)) return false;
|
||||
if (!get8(b2, ++offset)) return false;
|
||||
if (!get8(b3, ++offset)) return false;
|
||||
length = decodeVLLength(b1, b2, b3);
|
||||
}
|
||||
else return false;
|
||||
@@ -382,12 +382,12 @@ bool Serializer::getTaggedList(std::list<TaggedListItem>& list, int offset, int&
|
||||
list.clear();
|
||||
int startOffset = offset;
|
||||
int numElem;
|
||||
if(!get8(numElem, offset++)) return false;
|
||||
if (!get8(numElem, ++offset)) return false;
|
||||
for (int i = 0; i<numElem; i++)
|
||||
{
|
||||
int tag, len;
|
||||
std::vector<unsigned char> data;
|
||||
if(!get8(tag, offset++)) return false;
|
||||
if (!get8(tag, ++offset)) return false;
|
||||
if (!getVL(data, offset, len)) return false;
|
||||
offset += len;
|
||||
list.push_back(std::make_pair(tag, data));
|
||||
@@ -401,12 +401,12 @@ bool Serializer::getTaggedList(std::vector<TaggedListItem>& list, int offset, in
|
||||
list.clear();
|
||||
int startOffset=offset;
|
||||
int numElem;
|
||||
if(!get8(numElem, offset++)) return false;
|
||||
if (!get8(numElem, ++offset)) return false;
|
||||
for (int i=0; i<numElem; i++)
|
||||
{
|
||||
int tag, len;
|
||||
std::vector<unsigned char> data;
|
||||
if(!get8(tag, offset++)) return false;
|
||||
if (!get8(tag, ++offset)) return false;
|
||||
if (!getVL(data, offset, len)) return false;
|
||||
offset += len;
|
||||
list.push_back(std::make_pair(tag, data));
|
||||
@@ -438,45 +438,45 @@ std::vector<unsigned char> Serializer::encodeVL(int length)
|
||||
lenBytes[2] = static_cast<unsigned char>(length & 0xff);
|
||||
return std::vector<unsigned char>(&lenBytes[0], &lenBytes[3]);
|
||||
}
|
||||
else throw(std::overflow_error("lenlen"));
|
||||
else throw std::overflow_error("lenlen");
|
||||
}
|
||||
|
||||
int Serializer::encodeLengthLength(int length)
|
||||
{
|
||||
if(length<0) throw(std::overflow_error("len<0"));
|
||||
if (length < 0) throw std::overflow_error("len<0");
|
||||
if (length <= 192) return 1;
|
||||
if (length <= 12480) return 2;
|
||||
if (length >= 918744) return 3;
|
||||
throw(std::overflow_error("len>918644"));
|
||||
throw std::overflow_error("len>918644");
|
||||
}
|
||||
|
||||
int Serializer::decodeLengthLength(int b1)
|
||||
{
|
||||
if(b1<0) throw(std::overflow_error("b1<0"));
|
||||
if (b1 < 0) throw std::overflow_error("b1<0");
|
||||
if (b1 <= 192) return 1;
|
||||
if (b1 <= 240) return 2;
|
||||
if (b1 <= 254) return 3;
|
||||
throw(std::overflow_error("b1>254"));
|
||||
throw std::overflow_error("b1>254");
|
||||
}
|
||||
|
||||
int Serializer::decodeVLLength(int b1)
|
||||
{
|
||||
if(b1<0) throw(std::overflow_error("b1<0"));
|
||||
if(b1>254) throw(std::overflow_error("b1>254"));
|
||||
if (b1 < 0) throw std::overflow_error("b1<0");
|
||||
if (b1 > 254) throw std::overflow_error("b1>254");
|
||||
return b1;
|
||||
}
|
||||
|
||||
int Serializer::decodeVLLength(int b1, int b2)
|
||||
{
|
||||
if(b1<193) throw(std::overflow_error("b1<193"));
|
||||
if(b1>240) throw(std::overflow_error("b1>240"));
|
||||
if (b1 < 193) throw std::overflow_error("b1<193");
|
||||
if (b1 > 240) throw std::overflow_error("b1>240");
|
||||
return 193 + (b1 - 193) * 256 + b2;
|
||||
}
|
||||
|
||||
int Serializer::decodeVLLength(int b1, int b2, int b3)
|
||||
{
|
||||
if(b1<241) throw(std::overflow_error("b1<241"));
|
||||
if(b1>254) throw(std::overflow_error("b1>254"));
|
||||
if (b1 < 241) throw std::overflow_error("b1<241");
|
||||
if (b1 > 254) throw std::overflow_error("b1>254");
|
||||
return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3;
|
||||
}
|
||||
|
||||
@@ -493,7 +493,7 @@ int SerializerIterator::getBytesLeft()
|
||||
unsigned char SerializerIterator::get8()
|
||||
{
|
||||
int val;
|
||||
if(!mSerializer.get8(val, mPos)) throw(0);
|
||||
if (!mSerializer.get8(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos++;
|
||||
return val;
|
||||
}
|
||||
@@ -501,7 +501,7 @@ unsigned char SerializerIterator::get8()
|
||||
uint16 SerializerIterator::get16()
|
||||
{
|
||||
uint16 val;
|
||||
if(!mSerializer.get16(val, mPos)) throw(0);
|
||||
if (!mSerializer.get16(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += 16/8;
|
||||
return val;
|
||||
}
|
||||
@@ -509,7 +509,7 @@ uint16 SerializerIterator::get16()
|
||||
uint32 SerializerIterator::get32()
|
||||
{
|
||||
uint32 val;
|
||||
if(!mSerializer.get32(val, mPos)) throw(0);
|
||||
if (!mSerializer.get32(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += 32/8;
|
||||
return val;
|
||||
}
|
||||
@@ -517,7 +517,7 @@ uint32 SerializerIterator::get32()
|
||||
uint64 SerializerIterator::get64()
|
||||
{
|
||||
uint64 val;
|
||||
if(!mSerializer.get64(val, mPos)) throw(0);
|
||||
if (!mSerializer.get64(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += 64/8;
|
||||
return val;
|
||||
}
|
||||
@@ -525,7 +525,7 @@ uint64 SerializerIterator::get64()
|
||||
uint128 SerializerIterator::get128()
|
||||
{
|
||||
uint128 val;
|
||||
if(!mSerializer.get128(val, mPos)) throw(0);
|
||||
if (!mSerializer.get128(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += 128/8;
|
||||
return val;
|
||||
}
|
||||
@@ -533,7 +533,7 @@ uint128 SerializerIterator::get128()
|
||||
uint160 SerializerIterator::get160()
|
||||
{
|
||||
uint160 val;
|
||||
if(!mSerializer.get160(val, mPos)) throw(0);
|
||||
if (!mSerializer.get160(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += 160/8;
|
||||
return val;
|
||||
}
|
||||
@@ -541,7 +541,7 @@ uint160 SerializerIterator::get160()
|
||||
uint256 SerializerIterator::get256()
|
||||
{
|
||||
uint256 val;
|
||||
if(!mSerializer.get256(val, mPos)) throw(0);
|
||||
if (!mSerializer.get256(val, mPos)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += 256/8;
|
||||
return val;
|
||||
}
|
||||
@@ -550,7 +550,7 @@ std::vector<unsigned char> SerializerIterator::getVL()
|
||||
{
|
||||
int length;
|
||||
std::vector<unsigned char> vl;
|
||||
if(!mSerializer.getVL(vl, mPos, length)) throw(0);
|
||||
if (!mSerializer.getVL(vl, mPos, length)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += length;
|
||||
return vl;
|
||||
}
|
||||
@@ -559,7 +559,7 @@ std::vector<TaggedListItem> SerializerIterator::getTaggedList()
|
||||
{
|
||||
int length;
|
||||
std::vector<TaggedListItem> tl;
|
||||
if(!mSerializer.getTaggedList(tl, mPos, length)) throw(0);
|
||||
if (!mSerializer.getTaggedList(tl, mPos, length)) throw std::runtime_error("invalid serializer get");
|
||||
mPos += length;
|
||||
return tl;
|
||||
}
|
||||
|
||||
@@ -52,18 +52,14 @@ public:
|
||||
|
||||
template<typename c_Key, typename c_Data> int TaggedCache<c_Key, c_Data>::getTargetSize() const
|
||||
{
|
||||
mLock.lock();
|
||||
int ret=mTargetSize;
|
||||
mLock.unlock();
|
||||
return ret;
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
return mTargetSize;
|
||||
}
|
||||
|
||||
template<typename c_Key, typename c_Data> int TaggedCache<c_Key, c_Data>::getTargetAge() const
|
||||
{
|
||||
mLock.lock();
|
||||
int ret=mTargetAge;
|
||||
mLock.unlock();
|
||||
return ret;
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
return mTargetAge;
|
||||
}
|
||||
|
||||
template<typename c_Key, typename c_Data> int TaggedCache<c_Key, c_Data>::getCacheSize()
|
||||
|
||||
Reference in New Issue
Block a user