mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
UPSTREAM MERGE BROKEN: Merge commit 'f617e05c38' into master
This commit is contained in:
commit
7f894ae00b
393 changed files with 7992 additions and 3340 deletions
100
src/rpc/util.cpp
100
src/rpc/util.cpp
|
|
@ -7,11 +7,13 @@
|
|||
#include <rpc/protocol.h>
|
||||
#include <rpc/util.h>
|
||||
#include <tinyformat.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <policy/policy.h>
|
||||
#include <assetsdir.h>
|
||||
#include <core_io.h>
|
||||
|
||||
InitInterfaces* g_rpc_interfaces = nullptr;
|
||||
|
||||
// Converts a hex string to a public key if possible
|
||||
CPubKey HexToPubKey(const std::string& hex_in)
|
||||
{
|
||||
|
|
@ -138,6 +140,99 @@ UniValue DescribeAddress(const CTxDestination& dest)
|
|||
return boost::apply_visitor(DescribeAddressVisitor(), dest);
|
||||
}
|
||||
|
||||
std::string RPCHelpMan::ToString() const
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
ret += m_name;
|
||||
bool is_optional{false};
|
||||
for (const auto& arg : m_args) {
|
||||
ret += " ";
|
||||
if (arg.m_optional) {
|
||||
if (!is_optional) ret += "( ";
|
||||
is_optional = true;
|
||||
} else {
|
||||
// Currently we still support unnamed arguments, so any argument following an optional argument must also be optional
|
||||
// If support for positional arguments is deprecated in the future, remove this line
|
||||
assert(!is_optional);
|
||||
}
|
||||
ret += arg.ToString();
|
||||
}
|
||||
if (is_optional) ret += " )";
|
||||
ret += "\n";
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string RPCArg::ToStringObj() const
|
||||
{
|
||||
std::string res = "\"" + m_name + "\":";
|
||||
switch (m_type) {
|
||||
case Type::STR:
|
||||
return res + "\"str\"";
|
||||
case Type::STR_HEX:
|
||||
return res + "\"hex\"";
|
||||
case Type::NUM:
|
||||
return res + "n";
|
||||
case Type::AMOUNT:
|
||||
return res + "amount";
|
||||
case Type::BOOL:
|
||||
return res + "bool";
|
||||
case Type::ARR:
|
||||
res += "[";
|
||||
for (const auto& i : m_inner) {
|
||||
res += i.ToString() + ",";
|
||||
}
|
||||
return res + "...]";
|
||||
case Type::OBJ:
|
||||
case Type::OBJ_USER_KEYS:
|
||||
// Currently unused, so avoid writing dead code
|
||||
assert(false);
|
||||
|
||||
// no default case, so the compiler can warn about missing cases
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
std::string RPCArg::ToString() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::STR_HEX:
|
||||
case Type::STR: {
|
||||
return "\"" + m_name + "\"";
|
||||
}
|
||||
case Type::NUM:
|
||||
case Type::AMOUNT:
|
||||
case Type::BOOL: {
|
||||
return m_name;
|
||||
}
|
||||
case Type::OBJ:
|
||||
case Type::OBJ_USER_KEYS: {
|
||||
std::string res;
|
||||
for (size_t i = 0; i < m_inner.size();) {
|
||||
res += m_inner[i].ToStringObj();
|
||||
if (++i < m_inner.size()) res += ",";
|
||||
}
|
||||
if (m_type == Type::OBJ) {
|
||||
return "{" + res + "}";
|
||||
} else {
|
||||
return "{" + res + ",...}";
|
||||
}
|
||||
}
|
||||
case Type::ARR: {
|
||||
std::string res;
|
||||
for (const auto& i : m_inner) {
|
||||
res += i.ToString() + ",";
|
||||
}
|
||||
return "[" + res + "...]";
|
||||
}
|
||||
|
||||
// no default case, so the compiler can warn about missing cases
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
//
|
||||
// ELEMENTS
|
||||
|
||||
class BlindingPubkeyVisitor : public boost::static_visitor<CPubKey>
|
||||
|
|
@ -306,3 +401,6 @@ UniValue AmountMapToUniv(const CAmountMap& balanceOrig, std::string strasset)
|
|||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// END ELEMENTS
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue