rippled
SignerEntries.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/app/tx/impl/SignerEntries.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/protocol/STArray.h>
23 #include <ripple/protocol/STObject.h>
24 #include <cstdint>
25 #include <optional>
26 
27 namespace ripple {
28 
29 Expected<std::vector<SignerEntries::SignerEntry>, NotTEC>
31  STObject const& obj,
32  beast::Journal journal,
33  std::string const& annotation)
34 {
36 
38  {
39  JLOG(journal.trace())
40  << "Malformed " << annotation << ": Need signer entry array.";
41  return Unexpected(temMALFORMED);
42  }
43 
44  std::vector<SignerEntry> accountVec;
45  accountVec.reserve(STTx::maxMultiSigners());
46 
47  STArray const& sEntries(obj.getFieldArray(sfSignerEntries));
48  for (STObject const& sEntry : sEntries)
49  {
50  // Validate the SignerEntry.
51  if (sEntry.getFName() != sfSignerEntry)
52  {
53  JLOG(journal.trace())
54  << "Malformed " << annotation << ": Expected SignerEntry.";
55  return Unexpected(temMALFORMED);
56  }
57 
58  // Extract SignerEntry fields.
59  AccountID const account = sEntry.getAccountID(sfAccount);
60  std::uint16_t const weight = sEntry.getFieldU16(sfSignerWeight);
61  std::optional<uint256> const tag = sEntry.at(~sfWalletLocator);
62 
63  accountVec.emplace_back(account, weight, tag);
64  }
65  return accountVec;
66 }
67 
68 } // namespace ripple
ripple::sfSignerWeight
const SF_UINT16 sfSignerWeight
ripple::STObject::getFieldArray
const STArray & getFieldArray(SField const &field) const
Definition: STObject.cpp:624
std::string
STL class.
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::SignerEntries::deserialize
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string const &annotation)
Definition: SignerEntries.cpp:30
std::pair
std::vector::reserve
T reserve(T... args)
std::vector
STL class.
ripple::Unexpected
Unexpected(E(&)[N]) -> Unexpected< E const * >
ripple::base_uint< 160, detail::AccountIDTag >
ripple::TERSubset
Definition: TER.h:340
ripple::STArray
Definition: STArray.h:28
cstdint
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::STTx::maxMultiSigners
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition: STTx.h:55
std::uint16_t
ripple::sfSignerEntry
const SField sfSignerEntry
ripple::sfSignerEntries
const SField sfSignerEntries
ripple::STObject
Definition: STObject.h:51
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::sfWalletLocator
const SF_UINT256 sfWalletLocator
ripple::STObject::isFieldPresent
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:428
optional
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::temMALFORMED
@ temMALFORMED
Definition: TER.h:85
ripple::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:528