Files
xahaud/src/ripple/protocol/impl/STAccount.cpp
Scott Schurr f72b14ec36 Make STAccount only constructible with 160 bits (RIPD-994):
If someone attempts to construct an STAccount with something
other than 160 bits the constructor now throws.

Since an STAccount now enforces that it always stores exactly
160 bits, we use a fixed-sized uint160 for the storage, replacing
a variable sized STBlob.

In order to leave the ledger and wire formats unaffected, the
STAccount still serializes and deserializes itself as though
it were variable length.
2015-11-24 01:33:53 -08:00

77 lines
2.3 KiB
C++

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/protocol/STAccount.h>
namespace ripple {
STAccount::STAccount ()
: STBase ()
, value_ (beast::zero)
, default_ (true)
{
}
STAccount::STAccount (SField const& n)
: STBase (n)
, value_ (beast::zero)
, default_ (true)
{
}
STAccount::STAccount (SField const& n, Buffer&& v)
: STAccount (n)
{
if (v.empty())
return; // Zero is a valid size for a defaulted STAccount.
// Is it safe to throw from this constructor? Today (November 2015)
// the only place that calls this constructor is
// STVar::STVar (SerialIter&, SField const&)
// which throws. If STVar can throw in its constructor, then so can
// STAccount.
if (v.size() != uint160::bytes)
throw std::runtime_error ("Invalid STAccount size");
default_ = false;
memcpy (value_.begin(), v.data (), uint160::bytes);
}
STAccount::STAccount (SerialIter& sit, SField const& name)
: STAccount(name, sit.getVLBuffer())
{
}
STAccount::STAccount (SField const& n, AccountID const& v)
: STBase (n)
, default_ (false)
{
value_.copyFrom (v);
}
std::string STAccount::getText () const
{
if (isDefault())
return "";
return toBase58 (value());
}
} // ripple