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