@@ -165,13 +165,21 @@ UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_s
165
165
}
166
166
}
167
167
168
+ /* *
169
+ * A pair of strings that can be aligned (through padding) with other Sections
170
+ * later on
171
+ */
168
172
struct Section {
169
173
Section (const std::string& left, const std::string& right)
170
174
: m_left{left}, m_right{right} {}
171
175
const std::string m_left;
172
176
const std::string m_right;
173
177
};
174
178
179
+ /* *
180
+ * Keeps track of RPCArgs by transforming them into sections for the purpose
181
+ * of serializing everything to a single string
182
+ */
175
183
struct Sections {
176
184
std::vector<Section> m_sections;
177
185
size_t m_max_pad{0 };
@@ -182,12 +190,20 @@ struct Sections {
182
190
m_sections.push_back (s);
183
191
}
184
192
193
+ /* *
194
+ * Serializing RPCArgs depends on the outer type. Only arrays and
195
+ * dictionaries can be nested in json. The top-level outer type is "named
196
+ * arguments", a mix between a dictionary and arrays.
197
+ */
185
198
enum class OuterType {
186
199
ARR,
187
200
OBJ,
188
201
NAMED_ARG, // Only set on first recursion
189
202
};
190
203
204
+ /* *
205
+ * Recursive helper to translate an RPCArg into sections
206
+ */
191
207
void Push (const RPCArg& arg, const size_t current_indent = 5 , const OuterType outer_type = OuterType::NAMED_ARG)
192
208
{
193
209
const auto indent = std::string (current_indent, ' ' );
@@ -241,6 +257,9 @@ struct Sections {
241
257
}
242
258
}
243
259
260
+ /* *
261
+ * Concatenate all sections with proper padding
262
+ */
244
263
std::string ToString () const
245
264
{
246
265
std::string ret;
0 commit comments