mirror of
https://codeberg.org/wownero/wownero-lws
synced 2026-01-09 23:25:16 -08:00
Update ::wire:: to be closer to Monero variant (#70)
This commit is contained in:
committed by
Lee *!* Clagett
parent
3e0555e07d
commit
e1bd9541f1
@@ -30,4 +30,4 @@ set(monero-lws-rpc_sources admin.cpp client.cpp daemon_pub.cpp daemon_zmq.cpp li
|
||||
set(monero-lws-rpc_headers admin.h client.h daemon_pub.h daemon_zmq.h fwd.h json.h light_wallet.h rates.h)
|
||||
|
||||
add_library(monero-lws-rpc ${monero-lws-rpc_sources} ${monero-lws-rpc_headers})
|
||||
target_link_libraries(monero-lws-rpc monero::libraries monero-lws-wire-json)
|
||||
target_link_libraries(monero-lws-rpc monero::libraries monero-lws-wire-json monero-lws-wire-wrapper)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "admin.h"
|
||||
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
#include <functional>
|
||||
@@ -41,6 +42,8 @@
|
||||
#include "wire/traits.h"
|
||||
#include "wire/uuid.h"
|
||||
#include "wire/vector.h"
|
||||
#include "wire/wrapper/array.h"
|
||||
#include "wire/wrappers_impl.h"
|
||||
|
||||
namespace wire
|
||||
{
|
||||
@@ -94,7 +97,7 @@ namespace
|
||||
void write_bytes(wire::json_writer& dest, const truncated<boost::iterator_range<lmdb::value_iterator<V>>> self)
|
||||
{
|
||||
const auto truncate = [] (V src) { return truncated<V>{std::move(src)}; };
|
||||
wire::array(dest, std::move(self.value), truncate);
|
||||
wire_write::bytes(dest, wire::array(boost::adaptors::transform(std::move(self.value), truncate)));
|
||||
}
|
||||
|
||||
template<typename K, typename V, typename C>
|
||||
@@ -127,7 +130,10 @@ namespace
|
||||
void write_addresses(wire::writer& dest, epee::span<const lws::db::account_address> self)
|
||||
{
|
||||
// writes an array of monero base58 address strings
|
||||
wire::object(dest, wire::field("updated", wire::as_array(self, lws::db::address_string)));
|
||||
|
||||
wire::object(dest,
|
||||
wire::field("updated", wire::array(boost::adaptors::transform(self, lws::db::address_string)))
|
||||
);
|
||||
}
|
||||
|
||||
expect<void> write_addresses(wire::writer& dest, const expect<std::vector<lws::db::account_address>>& self)
|
||||
|
||||
@@ -77,7 +77,11 @@ namespace rpc
|
||||
|
||||
expect<minimal_chain_pub> minimal_chain_pub::from_json(std::string&& source)
|
||||
{
|
||||
return wire::json::from_bytes<minimal_chain_pub>(std::move(source));
|
||||
minimal_chain_pub out{};
|
||||
std::error_code err = wire::json::from_bytes(std::move(source), out);
|
||||
if (err)
|
||||
return err;
|
||||
return {std::move(out)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "rpc/message_data_structs.h" // monero/src
|
||||
#include "wire/crypto.h"
|
||||
#include "wire/json.h"
|
||||
#include "wire/wrapper/variant.h"
|
||||
#include "wire/vector.h"
|
||||
|
||||
namespace
|
||||
@@ -103,14 +104,13 @@ namespace cryptonote
|
||||
}
|
||||
static void read_bytes(wire::json_reader& source, tx_out& self)
|
||||
{
|
||||
auto variant = wire::variant(std::ref(self.target));
|
||||
wire::object(source,
|
||||
WIRE_FIELD(amount),
|
||||
wire::variant_field("transaction output variant", std::ref(self.target),
|
||||
wire::option<txout_to_key>{"to_key"},
|
||||
wire::option<txout_to_tagged_key>{"to_tagged_key"},
|
||||
wire::option<txout_to_script>{"to_script"},
|
||||
wire::option<txout_to_scripthash>{"to_scripthash"}
|
||||
)
|
||||
WIRE_OPTION("to_key", txout_to_key, variant),
|
||||
WIRE_OPTION("to_tagged_key", txout_to_tagged_key, variant),
|
||||
WIRE_OPTION("to_script", txout_to_script, variant),
|
||||
WIRE_OPTION("to_scripthash", txout_to_scripthash, variant)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,13 +132,12 @@ namespace cryptonote
|
||||
}
|
||||
static void read_bytes(wire::json_reader& source, txin_v& self)
|
||||
{
|
||||
auto variant = wire::variant(std::ref(self));
|
||||
wire::object(source,
|
||||
wire::variant_field("transaction input variant", std::ref(self),
|
||||
wire::option<txin_to_key>{"to_key"},
|
||||
wire::option<txin_gen>{"gen"},
|
||||
wire::option<txin_to_script>{"to_script"},
|
||||
wire::option<txin_to_scripthash>{"to_scripthash"}
|
||||
)
|
||||
WIRE_OPTION("to_key", txin_to_key, variant),
|
||||
WIRE_OPTION("gen", txin_gen, variant),
|
||||
WIRE_OPTION("to_script", txin_to_script, variant),
|
||||
WIRE_OPTION("to_scripthash", txin_to_scripthash, variant)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "light_wallet.h"
|
||||
|
||||
#include <boost/range/adaptor/indexed.hpp>
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
@@ -44,6 +45,8 @@
|
||||
#include "wire/json.h"
|
||||
#include "wire/traits.h"
|
||||
#include "wire/vector.h"
|
||||
#include "wire/wrapper/array.h"
|
||||
#include "wire/wrappers_impl.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -261,7 +264,7 @@ namespace lws
|
||||
WIRE_FIELD_COPY(start_height),
|
||||
WIRE_FIELD_COPY(transaction_height),
|
||||
WIRE_FIELD_COPY(blockchain_height),
|
||||
wire::field("transactions", wire::as_array(boost::adaptors::index(self.transactions)))
|
||||
wire::field("transactions", wire::array(boost::adaptors::index(self.transactions)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -297,7 +300,7 @@ namespace lws
|
||||
WIRE_FIELD_COPY(per_byte_fee),
|
||||
WIRE_FIELD_COPY(fee_mask),
|
||||
WIRE_FIELD_COPY(amount),
|
||||
wire::field("outputs", wire::as_array(std::cref(self.outputs), expand))
|
||||
wire::field("outputs", wire::array(boost::adaptors::transform(self.outputs, expand)))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,11 @@ namespace lws
|
||||
|
||||
expect<lws::rates> crypto_compare_::operator()(std::string&& body) const
|
||||
{
|
||||
return wire::json::from_bytes<lws::rates>(std::move(body));
|
||||
lws::rates out{};
|
||||
const std::error_code error = wire::json::from_bytes(std::move(body), out);
|
||||
if (error)
|
||||
return error;
|
||||
return {std::move(out)};
|
||||
}
|
||||
} // rpc
|
||||
} // lws
|
||||
|
||||
Reference in New Issue
Block a user