/
SetSignerList.h
195 lines (162 loc) · 6.17 KB
/
SetSignerList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2014 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.
*/
//==============================================================================
#ifndef RIPPLE_TX_SETSIGNERLIST_H_INCLUDED
#define RIPPLE_TX_SETSIGNERLIST_H_INCLUDED
#include <ripple/app/ledger/Ledger.h>
#include <ripple/app/tx/impl/SignerEntries.h>
#include <ripple/app/tx/impl/Transactor.h>
#include <ripple/basics/Log.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/Rules.h>
#include <ripple/protocol/STArray.h>
#include <ripple/protocol/STObject.h>
#include <ripple/protocol/STTx.h>
#include <algorithm>
#include <cstdint>
#include <vector>
namespace ripple {
/**
See the README.md for an overview of the SetSignerList transaction that
this class implements.
*/
class SetSignerList : public Transactor
{
private:
// Values determined during preCompute for use later.
enum Operation { unknown, set, destroy };
Operation do_{unknown};
std::uint32_t quorum_{0};
std::vector<SignerEntries::SignerEntry> signers_;
public:
static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker};
explicit SetSignerList(ApplyContext& ctx) : Transactor(ctx)
{
}
static NotTEC
preflight(PreflightContext const& ctx);
TER
doApply() override;
void
preCompute() override;
// Interface used by DeleteAccount
static TER
removeFromLedger(
Application& app,
ApplyView& view,
AccountID const& account,
beast::Journal j);
static TER
removeSignersFromLedger(
Application& app,
ApplyView& view,
Keylet const& accountKeylet,
Keylet const& ownerDirKeylet,
Keylet const& signerListKeylet,
beast::Journal j);
static int
signerCountBasedOwnerCountDelta(std::size_t entryCount, Rules const& rules);
private:
static void
writeSignersToSLE(
ApplyView& view,
SLE::pointer const& ledgerEntry,
std::uint32_t flags,
std::uint32_t quorum,
std::vector<SignerEntries::SignerEntry> const& signers);
static std::tuple<
NotTEC,
std::uint32_t,
std::vector<SignerEntries::SignerEntry>,
Operation>
determineOperation(STTx const& tx, ApplyFlags flags, beast::Journal j);
TER
replaceSignerList();
TER
destroySignerList();
void
writeSignersToSLE(SLE::pointer const& ledgerEntry, std::uint32_t flags)
const;
public:
static NotTEC
validateQuorumAndSignerEntries(
std::uint32_t quorum,
std::vector<SignerEntries::SignerEntry> const& signers,
AccountID const& account,
beast::Journal j,
Rules const&);
template <typename V>
static TER
replaceSignersFromLedger(
Application& app,
V& view,
beast::Journal j,
AccountID const& acc,
std::uint32_t quorum,
std::vector<SignerEntries::SignerEntry> const& signers,
XRPAmount const mPriorBalance)
{
auto const accountKeylet = keylet::account(acc);
auto const ownerDirKeylet = keylet::ownerDir(acc);
auto const signerListKeylet = keylet::signers(acc);
// This may be either a create or a replace. Preemptively remove any
// old signer list. May reduce the reserve, so this is done before
// checking the reserve.
if (TER const ter = removeSignersFromLedger(
app, view, accountKeylet, ownerDirKeylet, signerListKeylet, j))
return ter;
auto const sle = view.peek(accountKeylet);
if (!sle)
return tefINTERNAL;
// Compute new reserve. Verify the account has funds to meet the
// reserve.
std::uint32_t const oldOwnerCount{(*sle)[sfOwnerCount]};
// The required reserve changes based on featureMultiSignReserve...
int addedOwnerCount{1};
std::uint32_t flags{lsfOneOwnerCount};
if (!view.rules().enabled(featureMultiSignReserve))
{
addedOwnerCount =
signerCountBasedOwnerCountDelta(signers.size(), view.rules());
flags = 0;
}
XRPAmount const newReserve{
view.fees().accountReserve(oldOwnerCount + addedOwnerCount)};
// We check the reserve against the starting balance because we want to
// allow dipping into the reserve to pay fees. This behavior is
// consistent with CreateTicket.
if (mPriorBalance < newReserve)
return tecINSUFFICIENT_RESERVE;
// Everything's ducky. Add the ltSIGNER_LIST to the ledger.
auto signerList = std::make_shared<SLE>(signerListKeylet);
view.insert(signerList);
writeSignersToSLE(view, signerList, flags, quorum, signers);
// Add the signer list to the account's directory.
auto const page = view.dirInsert(
ownerDirKeylet, signerListKeylet, describeOwnerDir(acc));
JLOG(j.trace()) << "Create signer list for account " << toBase58(acc)
<< ": " << (page ? "success" : "failure");
if (!page)
return tecDIR_FULL;
signerList->setFieldU64(sfOwnerNode, *page);
// If we succeeded, the new entry counts against the
// creator's reserve.
adjustOwnerCount(view, sle, addedOwnerCount, j);
return tesSUCCESS;
}
};
} // namespace ripple
#endif