rippled
STAccount.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/protocol/STAccount.h>
21 
22 #include <cstring>
23 
24 namespace ripple {
25 
26 STAccount::STAccount() : STBase(), value_(beast::zero), default_(true)
27 {
28 }
29 
31  : STBase(n), value_(beast::zero), default_(true)
32 {
33 }
34 
36 {
37  if (v.empty())
38  return; // Zero is a valid size for a defaulted STAccount.
39 
40  // Is it safe to throw from this constructor? Today (November 2015)
41  // the only place that calls this constructor is
42  // STVar::STVar (SerialIter&, SField const&)
43  // which throws. If STVar can throw in its constructor, then so can
44  // STAccount.
45  if (v.size() != uint160::bytes)
46  Throw<std::runtime_error>("Invalid STAccount size");
47 
48  default_ = false;
49  memcpy(value_.begin(), v.data(), uint160::bytes);
50 }
51 
53  : STAccount(name, sit.getVLBuffer())
54 {
55 }
56 
58  : STBase(n), value_(v), default_(false)
59 {
60 }
61 
64 {
65  if (isDefault())
66  return "";
67  return toBase58(value());
68 }
69 
70 } // namespace ripple
std::string
STL class.
cstring
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:29
ripple::Buffer
Like std::vector<char> but better.
Definition: Buffer.h:35
ripple::STAccount::isDefault
bool isDefault() const override
Definition: STAccount.h:90
ripple::STAccount::STAccount
STAccount()
Definition: STAccount.cpp:26
ripple::STAccount::default_
bool default_
Definition: STAccount.h:37
ripple::base_uint< 160, detail::AccountIDTag >
ripple::base_uint::bytes
static constexpr std::size_t bytes
Definition: base_uint.h:96
ripple::STAccount::value_
AccountID value_
Definition: STAccount.h:36
ripple::SerialIter
Definition: Serializer.h:308
ripple::STAccount::value
AccountID value() const noexcept
Definition: STAccount.h:103
ripple::STAccount
Definition: STAccount.h:29
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::base_uint::begin
iterator begin()
Definition: base_uint.h:124
ripple::STAccount::getText
std::string getText() const override
Definition: STAccount.cpp:63
ripple::SField
Identifies fields.
Definition: SField.h:109
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:62
beast
Definition: base_uint.h:585