aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-11-25 19:47:05 +0200
committerRiccardo Spagni <ric@spagni.net>2017-11-25 19:47:05 +0200
commitd80a3e5c38fe1775d73ac98b668ebb2d44953c4f (patch)
tree0ae9d4474bd411871c315a0d43bcdbd0e80b517d /src/wallet
parentMerge pull request #2785 (diff)
parentwallet_rpc_server: new relay_tx command (diff)
downloadmonero-d80a3e5c38fe1775d73ac98b668ebb2d44953c4f.tar.xz
Merge pull request #2788
9739da1e wallet_rpc_server: new relay_tx command (moneromooo-monero) 01dc8297 wallet: transfer RPC can now return tx metadata (pending_tx) (moneromooo-monero) 83fa9047 serialization: add std::set and std::unordered_set serialization (moneromooo-monero)
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.h27
-rw-r--r--src/wallet/wallet_rpc_server.cpp83
-rw-r--r--src/wallet/wallet_rpc_server.h2
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h47
-rw-r--r--src/wallet/wallet_rpc_server_error_codes.h2
5 files changed, 158 insertions, 3 deletions
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 671c0ca7e..8284fcd73 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -292,6 +292,19 @@ namespace tools
std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
uint32_t subaddr_account; // subaddress account of your wallet to be used in this transfer
std::set<uint32_t> subaddr_indices; // set of address indices used as inputs in this transfer
+
+ BEGIN_SERIALIZE_OBJECT()
+ FIELD(sources)
+ FIELD(change_dts)
+ FIELD(splitted_dsts)
+ FIELD(selected_transfers)
+ FIELD(extra)
+ FIELD(unlock_time)
+ FIELD(use_rct)
+ FIELD(dests)
+ FIELD(subaddr_account)
+ FIELD(subaddr_indices)
+ END_SERIALIZE()
};
typedef std::vector<transfer_details> transfer_container;
@@ -313,6 +326,20 @@ namespace tools
std::vector<cryptonote::tx_destination_entry> dests;
tx_construction_data construction_data;
+
+ BEGIN_SERIALIZE_OBJECT()
+ FIELD(tx)
+ FIELD(dust)
+ FIELD(fee)
+ FIELD(dust_added_to_fee)
+ FIELD(change_dts)
+ FIELD(selected_transfers)
+ FIELD(key_images)
+ FIELD(tx_key)
+ FIELD(additional_tx_keys)
+ FIELD(dests)
+ FIELD(construction_data)
+ END_SERIALIZE()
};
// The term "Unsigned tx" is not really a tx since it's not signed yet.
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 101cfe50f..666981918 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -30,6 +30,7 @@
#include <boost/format.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/filesystem/operations.hpp>
+#include <boost/algorithm/string.hpp>
#include <cstdint>
#include "include_base_utils.h"
using namespace epee;
@@ -635,6 +636,13 @@ namespace tools
tx_to_blob(ptx_vector.back().tx, blob);
res.tx_blob = epee::string_tools::buff_to_hex_nodelimer(blob);
}
+ if (req.get_tx_metadata)
+ {
+ std::ostringstream oss;
+ binary_archive<true> ar(oss);
+ ::serialization::serialize(ar, ptx_vector.back());
+ res.tx_metadata = epee::string_tools::buff_to_hex_nodelimer(oss.str());
+ }
return true;
}
catch (const std::exception& e)
@@ -682,7 +690,7 @@ namespace tools
}
// populate response with tx hashes
- for (auto & ptx : ptx_vector)
+ for (const auto & ptx : ptx_vector)
{
res.tx_hash_list.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx)));
if (req.get_tx_keys)
@@ -705,6 +713,13 @@ namespace tools
tx_to_blob(ptx.tx, blob);
res.tx_blob_list.push_back(epee::string_tools::buff_to_hex_nodelimer(blob));
}
+ if (req.get_tx_metadata)
+ {
+ std::ostringstream oss;
+ binary_archive<true> ar(oss);
+ ::serialization::serialize(ar, const_cast<tools::wallet2::pending_tx&>(ptx));
+ res.tx_metadata_list.push_back(epee::string_tools::buff_to_hex_nodelimer(oss.str()));
+ }
}
return true;
@@ -735,7 +750,7 @@ namespace tools
m_wallet->commit_tx(ptx_vector);
// populate response with tx hashes
- for (auto & ptx : ptx_vector)
+ for (const auto & ptx : ptx_vector)
{
res.tx_hash_list.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx)));
if (req.get_tx_keys)
@@ -749,6 +764,13 @@ namespace tools
tx_to_blob(ptx.tx, blob);
res.tx_blob_list.push_back(epee::string_tools::buff_to_hex_nodelimer(blob));
}
+ if (req.get_tx_metadata)
+ {
+ std::ostringstream oss;
+ binary_archive<true> ar(oss);
+ ::serialization::serialize(ar, const_cast<tools::wallet2::pending_tx&>(ptx));
+ res.tx_metadata_list.push_back(epee::string_tools::buff_to_hex_nodelimer(oss.str()));
+ }
}
return true;
@@ -793,7 +815,7 @@ namespace tools
m_wallet->commit_tx(ptx_vector);
// populate response with tx hashes
- for (auto & ptx : ptx_vector)
+ for (const auto & ptx : ptx_vector)
{
res.tx_hash_list.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx)));
if (req.get_tx_keys)
@@ -806,6 +828,13 @@ namespace tools
tx_to_blob(ptx.tx, blob);
res.tx_blob_list.push_back(epee::string_tools::buff_to_hex_nodelimer(blob));
}
+ if (req.get_tx_metadata)
+ {
+ std::ostringstream oss;
+ binary_archive<true> ar(oss);
+ ::serialization::serialize(ar, const_cast<tools::wallet2::pending_tx&>(ptx));
+ res.tx_metadata_list.push_back(epee::string_tools::buff_to_hex_nodelimer(oss.str()));
+ }
}
return true;
@@ -889,6 +918,13 @@ namespace tools
tx_to_blob(ptx.tx, blob);
res.tx_blob = epee::string_tools::buff_to_hex_nodelimer(blob);
}
+ if (req.get_tx_metadata)
+ {
+ std::ostringstream oss;
+ binary_archive<true> ar(oss);
+ ::serialization::serialize(ar, const_cast<tools::wallet2::pending_tx&>(ptx));
+ res.tx_metadata = epee::string_tools::buff_to_hex_nodelimer(oss.str());
+ }
return true;
}
@@ -913,6 +949,47 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_relay_tx(const wallet_rpc::COMMAND_RPC_RELAY_TX::request& req, wallet_rpc::COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& er)
+ {
+ if (!m_wallet) return not_open(er);
+
+ cryptonote::blobdata blob;
+ if (!epee::string_tools::parse_hexstr_to_binbuff(req.hex, blob))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_BAD_HEX;
+ er.message = "Failed to parse hex.";
+ return false;
+ }
+
+ std::stringstream ss;
+ ss << blob;
+ binary_archive<false> ba(ss);
+
+ tools::wallet2::pending_tx ptx;
+ bool r = ::serialization::serialize(ba, ptx);
+ if (!r)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_BAD_TX_METADATA;
+ er.message = "Failed to parse tx metadata.";
+ return false;
+ }
+
+ try
+ {
+ m_wallet->commit_tx(ptx);
+ }
+ catch(const std::exception &e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
+ er.message = "Failed to commit tx.";
+ return false;
+ }
+
+ res.tx_hash = epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx));
+
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er)
{
if (!m_wallet) return not_open(er);
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 87e442bae..80f98c98f 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -80,6 +80,7 @@ namespace tools
MAP_JON_RPC_WE("sweep_dust", on_sweep_dust, wallet_rpc::COMMAND_RPC_SWEEP_DUST)
MAP_JON_RPC_WE("sweep_all", on_sweep_all, wallet_rpc::COMMAND_RPC_SWEEP_ALL)
MAP_JON_RPC_WE("sweep_single", on_sweep_single, wallet_rpc::COMMAND_RPC_SWEEP_SINGLE)
+ MAP_JON_RPC_WE("relay_tx", on_relay_tx, wallet_rpc::COMMAND_RPC_RELAY_TX)
MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE)
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS)
MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS)
@@ -132,6 +133,7 @@ namespace tools
bool on_sweep_dust(const wallet_rpc::COMMAND_RPC_SWEEP_DUST::request& req, wallet_rpc::COMMAND_RPC_SWEEP_DUST::response& res, epee::json_rpc::error& er);
bool on_sweep_all(const wallet_rpc::COMMAND_RPC_SWEEP_ALL::request& req, wallet_rpc::COMMAND_RPC_SWEEP_ALL::response& res, epee::json_rpc::error& er);
bool on_sweep_single(const wallet_rpc::COMMAND_RPC_SWEEP_SINGLE::request& req, wallet_rpc::COMMAND_RPC_SWEEP_SINGLE::response& res, epee::json_rpc::error& er);
+ bool on_relay_tx(const wallet_rpc::COMMAND_RPC_RELAY_TX::request& req, wallet_rpc::COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& er);
bool on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er);
bool on_split_integrated_address(const wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er);
bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 2e7c7c76f..ee6fab84a 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -291,6 +291,7 @@ namespace wallet_rpc
bool get_tx_key;
bool do_not_relay;
bool get_tx_hex;
+ bool get_tx_metadata;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(destinations)
@@ -303,6 +304,7 @@ namespace wallet_rpc
KV_SERIALIZE(get_tx_key)
KV_SERIALIZE_OPT(do_not_relay, false)
KV_SERIALIZE_OPT(get_tx_hex, false)
+ KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
@@ -313,6 +315,7 @@ namespace wallet_rpc
std::list<std::string> amount_keys;
uint64_t fee;
std::string tx_blob;
+ std::string tx_metadata;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash)
@@ -320,6 +323,7 @@ namespace wallet_rpc
KV_SERIALIZE(amount_keys)
KV_SERIALIZE(fee)
KV_SERIALIZE(tx_blob)
+ KV_SERIALIZE(tx_metadata)
END_KV_SERIALIZE_MAP()
};
};
@@ -338,6 +342,7 @@ namespace wallet_rpc
bool get_tx_keys;
bool do_not_relay;
bool get_tx_hex;
+ bool get_tx_metadata;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(destinations)
@@ -350,6 +355,7 @@ namespace wallet_rpc
KV_SERIALIZE(get_tx_keys)
KV_SERIALIZE_OPT(do_not_relay, false)
KV_SERIALIZE_OPT(get_tx_hex, false)
+ KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
@@ -369,6 +375,7 @@ namespace wallet_rpc
std::list<uint64_t> amount_list;
std::list<uint64_t> fee_list;
std::list<std::string> tx_blob_list;
+ std::list<std::string> tx_metadata_list;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash_list)
@@ -376,6 +383,7 @@ namespace wallet_rpc
KV_SERIALIZE(amount_list)
KV_SERIALIZE(fee_list)
KV_SERIALIZE(tx_blob_list)
+ KV_SERIALIZE(tx_metadata_list)
END_KV_SERIALIZE_MAP()
};
};
@@ -387,11 +395,13 @@ namespace wallet_rpc
bool get_tx_keys;
bool do_not_relay;
bool get_tx_hex;
+ bool get_tx_metadata;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(get_tx_keys)
KV_SERIALIZE_OPT(do_not_relay, false)
KV_SERIALIZE_OPT(get_tx_hex, false)
+ KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
@@ -410,12 +420,14 @@ namespace wallet_rpc
std::list<std::string> tx_key_list;
std::list<uint64_t> fee_list;
std::list<std::string> tx_blob_list;
+ std::list<std::string> tx_metadata_list;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash_list)
KV_SERIALIZE(tx_key_list)
KV_SERIALIZE(fee_list)
KV_SERIALIZE(tx_blob_list)
+ KV_SERIALIZE(tx_metadata_list)
END_KV_SERIALIZE_MAP()
};
};
@@ -435,6 +447,7 @@ namespace wallet_rpc
uint64_t below_amount;
bool do_not_relay;
bool get_tx_hex;
+ bool get_tx_metadata;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
@@ -448,6 +461,7 @@ namespace wallet_rpc
KV_SERIALIZE(below_amount)
KV_SERIALIZE_OPT(do_not_relay, false)
KV_SERIALIZE_OPT(get_tx_hex, false)
+ KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
@@ -466,12 +480,14 @@ namespace wallet_rpc
std::list<std::string> tx_key_list;
std::list<uint64_t> fee_list;
std::list<std::string> tx_blob_list;
+ std::list<std::string> tx_metadata_list;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash_list)
KV_SERIALIZE(tx_key_list)
KV_SERIALIZE(fee_list)
KV_SERIALIZE(tx_blob_list)
+ KV_SERIALIZE(tx_metadata_list)
END_KV_SERIALIZE_MAP()
};
};
@@ -489,6 +505,7 @@ namespace wallet_rpc
std::string key_image;
bool do_not_relay;
bool get_tx_hex;
+ bool get_tx_metadata;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
@@ -500,6 +517,36 @@ namespace wallet_rpc
KV_SERIALIZE(key_image)
KV_SERIALIZE_OPT(do_not_relay, false)
KV_SERIALIZE_OPT(get_tx_hex, false)
+ KV_SERIALIZE_OPT(get_tx_metadata, false)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string tx_hash;
+ std::string tx_key;
+ uint64_t fee;
+ std::string tx_blob;
+ std::string tx_metadata;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(tx_hash)
+ KV_SERIALIZE(tx_key)
+ KV_SERIALIZE(fee)
+ KV_SERIALIZE(tx_blob)
+ KV_SERIALIZE(tx_metadata)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
+ struct COMMAND_RPC_RELAY_TX
+ {
+ struct request
+ {
+ std::string hex;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(hex)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h
index 74f2999b6..c3f3e20d1 100644
--- a/src/wallet/wallet_rpc_server_error_codes.h
+++ b/src/wallet/wallet_rpc_server_error_codes.h
@@ -56,3 +56,5 @@
#define WALLET_RPC_ERROR_CODE_NO_WALLET_DIR -23
#define WALLET_RPC_ERROR_CODE_NO_TXKEY -24
#define WALLET_RPC_ERROR_CODE_WRONG_KEY -25
+#define WALLET_RPC_ERROR_CODE_BAD_HEX -26
+#define WALLET_RPC_ERROR_CODE_BAD_TX_METADATA -27