mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-12-02 05:04:04 +01:00
v0.5.4 updates
support freeze, thaw, and frozen include key images of spent outputs when txs created bump supported monero-project to v0.17.2.0 add cryptonote_format_utils_basic dependency
This commit is contained in:
+8
-1
@@ -173,6 +173,10 @@ set_target_properties(cryptonote_core PROPERTIES IMPORTED_LOCATION
|
||||
add_library(cryptonote_basic STATIC IMPORTED)
|
||||
set_target_properties(cryptonote_basic PROPERTIES IMPORTED_LOCATION
|
||||
${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_basic.a)
|
||||
|
||||
add_library(cryptonote_format_utils_basic STATIC IMPORTED)
|
||||
set_target_properties(cryptonote_format_utils_basic PROPERTIES IMPORTED_LOCATION
|
||||
${MONERO_PROJECT_BUILD}/src/cryptonote_basic/libcryptonote_format_utils_basic.a)
|
||||
|
||||
add_library(mnemonics STATIC IMPORTED)
|
||||
set_target_properties(mnemonics PROPERTIES IMPORTED_LOCATION
|
||||
@@ -257,6 +261,7 @@ if (BUILD_LIBRARY)
|
||||
|
||||
cryptonote_core
|
||||
cryptonote_basic
|
||||
cryptonote_format_utils_basic
|
||||
mnemonics
|
||||
ringct
|
||||
ringct_basic
|
||||
@@ -280,7 +285,7 @@ if (BUILD_LIBRARY)
|
||||
endif()
|
||||
|
||||
########################
|
||||
# Build C++ Sample Code
|
||||
# Build C++ sample Code
|
||||
########################
|
||||
|
||||
if (BUILD_SAMPLE)
|
||||
@@ -301,6 +306,7 @@ if (BUILD_SAMPLE)
|
||||
|
||||
cryptonote_core
|
||||
cryptonote_basic
|
||||
cryptonote_format_utils_basic
|
||||
mnemonics
|
||||
ringct
|
||||
ringct_basic
|
||||
@@ -345,6 +351,7 @@ if (BUILD_SCRATCHPAD)
|
||||
|
||||
cryptonote_core
|
||||
cryptonote_basic
|
||||
cryptonote_format_utils_basic
|
||||
mnemonics
|
||||
ringct
|
||||
ringct_basic
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Monero C++ Library
|
||||
|
||||
A C++ library for creating Monero applications using native bindings to [monero v0.17.1.9 'Oxygen Orion'](https://github.com/monero-project/monero/tree/v0.17.1.9).
|
||||
A C++ library for creating Monero applications using native bindings to [monero v0.17.2.0 'Oxygen Orion'](https://github.com/monero-project/monero/tree/v0.17.2.0).
|
||||
|
||||
* Supports fully client-side wallets by wrapping [wallet2.h](https://github.com/monero-project/monero/blob/master/src/wallet/wallet2.h).
|
||||
* Supports multisig, view-only, and offline wallets.
|
||||
@@ -20,8 +20,6 @@ A C++ library for creating Monero applications using native bindings to [monero
|
||||
|
||||
## Sample code
|
||||
|
||||
_Note: This API might change depending on feedback, such as changing structs to classes, using pure object-oriented accessors and mutators, not using boost::optional with shared_ptrs, etc. Feedback is welcome._
|
||||
|
||||
```c++
|
||||
// create a wallet from a mnemonic phrase
|
||||
string mnemonic = "hefty value later extra artistic firm radar yodel talent future fungal nutshell because sanity awesome nail unjustly rage unafraid cedar delayed thumbs comb custom sanity";
|
||||
@@ -171,7 +169,7 @@ wallet_random->close(true);
|
||||
## Documentation
|
||||
|
||||
* [API documentation](https://moneroecosystem.org/monero-cpp/annotated.html)
|
||||
* [API and model overview with visual diagrams](http://moneroecosystem.org/monero-java/monero-spec.pdf)
|
||||
* [API and model overview with visual diagrams](https://moneroecosystem.org/monero-java/monero-spec.pdf)
|
||||
* [monero-javascript documentation](https://github.com/monero-ecosystem/monero-javascript#documentation) provides additional documentation which translates to monero-cpp
|
||||
|
||||
## Using this library in your project
|
||||
|
||||
Vendored
+1
-1
Submodule external/monero-project updated: d3fd7d37f5...cd20d87dba
@@ -300,7 +300,7 @@ namespace monero {
|
||||
for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
|
||||
std::string key = it->first;
|
||||
if (key == std::string("hash")) tx->m_hash = it->second.data();
|
||||
else if (key == std::string("version")) throw std::runtime_error("version deserializationn not implemented");
|
||||
else if (key == std::string("version")) throw std::runtime_error("version deserialization not implemented");
|
||||
else if (key == std::string("isMinerTx")) tx->m_is_miner_tx = it->second.get_value<bool>();
|
||||
else if (key == std::string("paymentId")) tx->m_payment_id = it->second.data();
|
||||
else if (key == std::string("fee")) tx->m_fee = it->second.get_value<uint64_t>();
|
||||
@@ -321,8 +321,8 @@ namespace monero {
|
||||
else if (key == std::string("prunableHash")) tx->m_prunable_hash = it->second.data();
|
||||
else if (key == std::string("size")) tx->m_size = it->second.get_value<uint64_t>();
|
||||
else if (key == std::string("weight")) tx->m_weight = it->second.get_value<uint64_t>();
|
||||
else if (key == std::string("inputs")) throw std::runtime_error("inputs deserializationn not implemented");
|
||||
else if (key == std::string("outputs")) throw std::runtime_error("outputs deserializationn not implemented");
|
||||
else if (key == std::string("inputs")) throw std::runtime_error("inputs deserialization not implemented");
|
||||
else if (key == std::string("outputs")) throw std::runtime_error("outputs deserialization not implemented");
|
||||
else if (key == std::string("outputIndices")) throw std::runtime_error("m_output_indices deserialization not implemented");
|
||||
else if (key == std::string("metadata")) tx->m_metadata = it->second.data();
|
||||
else if (key == std::string("commonTxSets")) throw std::runtime_error("commonTxSets deserialization not implemented");
|
||||
@@ -379,7 +379,7 @@ namespace monero {
|
||||
tgt->m_outputs.push_back(output_copy);
|
||||
}
|
||||
}
|
||||
if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector<uint32_t>(src->m_output_indices);
|
||||
if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector<uint64_t>(src->m_output_indices);
|
||||
tgt->m_metadata = src->m_metadata;
|
||||
tgt->m_common_tx_sets = src->m_common_tx_sets;
|
||||
if (!src->m_extra.empty()) throw std::runtime_error("extra deep copy not implemented"); // TODO: implement extra
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace monero {
|
||||
boost::optional<uint64_t> m_weight;
|
||||
std::vector<std::shared_ptr<monero_output>> m_inputs;
|
||||
std::vector<std::shared_ptr<monero_output>> m_outputs;
|
||||
std::vector<uint32_t> m_output_indices;
|
||||
std::vector<uint64_t> m_output_indices;
|
||||
boost::optional<std::string> m_metadata;
|
||||
boost::optional<std::string> m_common_tx_sets;
|
||||
std::vector<uint8_t> m_extra;
|
||||
|
||||
@@ -787,6 +787,34 @@ namespace monero {
|
||||
throw std::runtime_error("import_key_images() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Freeze an output.
|
||||
*
|
||||
* @param key_image key image of the output to freeze
|
||||
*/
|
||||
virtual void freeze_output(const std::string& key_image) {
|
||||
throw std::runtime_error("freeze_output() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Thaw a frozen output.
|
||||
*
|
||||
* @param key_image key image of the output to thaw
|
||||
*/
|
||||
virtual void thaw_output(const std::string& key_image) {
|
||||
throw std::runtime_error("thaw_output() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an output is frozen.
|
||||
*
|
||||
* @param key_image key image of the output to check if frozen
|
||||
* @return true if the output is frozen, false otherwise
|
||||
*/
|
||||
virtual bool is_output_frozen(const std::string& key_image) {
|
||||
throw std::runtime_error("is_output_frozen() not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a transaction to transfer funds from this wallet.
|
||||
*
|
||||
|
||||
@@ -81,6 +81,15 @@ namespace monero {
|
||||
|
||||
// ----------------------- INTERNAL PRIVATE HELPERS -----------------------
|
||||
|
||||
struct key_image_list
|
||||
{
|
||||
std::list<std::string> key_images;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(key_images)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove query criteria which require looking up other transfers/outputs to
|
||||
* fulfill query.
|
||||
@@ -92,6 +101,7 @@ namespace monero {
|
||||
query->m_is_incoming = boost::none;
|
||||
query->m_is_outgoing = boost::none;
|
||||
query->m_transfer_query = boost::none;
|
||||
query->m_input_query = boost::none;
|
||||
query->m_output_query = boost::none;
|
||||
return query;
|
||||
}
|
||||
@@ -100,6 +110,7 @@ namespace monero {
|
||||
if (query.m_tx_query == boost::none) return false;
|
||||
if (query.m_tx_query.get()->m_is_incoming != boost::none) return true; // requires context of all transfers
|
||||
if (query.m_tx_query.get()->m_is_outgoing != boost::none) return true;
|
||||
if (query.m_tx_query.get()->m_input_query != boost::none) return true; // requires context of inputs
|
||||
if (query.m_tx_query.get()->m_output_query != boost::none) return true; // requires context of outputs
|
||||
return false;
|
||||
}
|
||||
@@ -370,7 +381,7 @@ namespace monero {
|
||||
output->m_subaddress_index = td.m_subaddr_index.minor;
|
||||
output->m_is_spent = td.m_spent;
|
||||
output->m_is_frozen = td.m_frozen;
|
||||
//output->m_stealth_public_key = epee::string_tools::pod_to_hex(td.get_public_key());
|
||||
//output->m_stealth_public_key = epee::string_tools::pod_to_hex(td.get_public_key()); // TODO (monero-wallet-rpc): provide this field
|
||||
if (td.m_key_image_known) {
|
||||
output->m_key_image = std::make_shared<monero_key_image>();
|
||||
output->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(td.m_key_image);
|
||||
@@ -606,10 +617,10 @@ namespace monero {
|
||||
return amount;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
template<typename Ts, typename Tu>
|
||||
template<typename Ts, typename Tu, typename Tk>
|
||||
bool fill_response(wallet2* m_w2, std::vector<tools::wallet2::pending_tx> &ptx_vector,
|
||||
bool get_tx_key, Ts& tx_key, Tu &amount, Tu &fee, Tu &weight, std::string &multisig_txset, std::string &unsigned_txset, bool do_not_relay,
|
||||
Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata, epee::json_rpc::error &er)
|
||||
Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata, Tk &spent_key_images, epee::json_rpc::error &er)
|
||||
{
|
||||
for (const auto & ptx : ptx_vector)
|
||||
{
|
||||
@@ -624,6 +635,17 @@ namespace monero {
|
||||
fill(amount, total_amount(ptx));
|
||||
fill(fee, ptx.fee);
|
||||
fill(weight, cryptonote::get_transaction_weight(ptx.tx));
|
||||
|
||||
// add spent key images
|
||||
key_image_list key_image_list;
|
||||
bool all_are_txin_to_key = std::all_of(ptx.tx.vin.begin(), ptx.tx.vin.end(), [&](const cryptonote::txin_v& s_e) -> bool
|
||||
{
|
||||
CHECKED_GET_SPECIFIC_VARIANT(s_e, const cryptonote::txin_to_key, in, false);
|
||||
key_image_list.key_images.push_back(epee::string_tools::pod_to_hex(in.k_image));
|
||||
return true;
|
||||
});
|
||||
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, ptx.tx);
|
||||
fill(spent_key_images, key_image_list);
|
||||
}
|
||||
|
||||
if (m_w2->multisig())
|
||||
@@ -1550,7 +1572,7 @@ namespace monero {
|
||||
|
||||
std::vector<std::shared_ptr<monero_tx_wallet>> monero_wallet_full::get_txs(const monero_tx_query& query) const {
|
||||
std::vector<std::string> missing_tx_hashes;
|
||||
std::vector<std::shared_ptr<monero_tx_wallet>> txs = monero_wallet_full::get_txs(query, missing_tx_hashes);
|
||||
std::vector<std::shared_ptr<monero_tx_wallet>> txs = get_txs(query, missing_tx_hashes);
|
||||
if (!missing_tx_hashes.empty()) throw std::runtime_error("Tx not found in wallet: " + missing_tx_hashes[0]);
|
||||
return txs;
|
||||
}
|
||||
@@ -1568,8 +1590,10 @@ namespace monero {
|
||||
|
||||
// temporarily disable transfer and output queries in order to collect all tx context
|
||||
boost::optional<std::shared_ptr<monero_transfer_query>> transfer_query = _query->m_transfer_query;
|
||||
boost::optional<std::shared_ptr<monero_output_query>> input_query = _query->m_input_query;
|
||||
boost::optional<std::shared_ptr<monero_output_query>> output_query = _query->m_output_query;
|
||||
_query->m_transfer_query = boost::none;
|
||||
_query->m_input_query = boost::none;
|
||||
_query->m_output_query = boost::none;
|
||||
|
||||
// fetch all transfers that meet tx query
|
||||
@@ -1615,6 +1639,7 @@ namespace monero {
|
||||
|
||||
// restore transfer and output queries
|
||||
_query->m_transfer_query = transfer_query;
|
||||
_query->m_input_query = input_query;
|
||||
_query->m_output_query = output_query;
|
||||
|
||||
// filter txs that don't meet transfer query
|
||||
@@ -1754,6 +1779,27 @@ namespace monero {
|
||||
return result;
|
||||
}
|
||||
|
||||
void monero_wallet_full::freeze_output(const std::string& key_image) {
|
||||
if (key_image.empty()) throw std::runtime_error("Must specify key image to freeze");
|
||||
crypto::key_image ki;
|
||||
if (!epee::string_tools::hex_to_pod(key_image, ki)) throw new std::runtime_error("failed to parse key imge");
|
||||
m_w2->freeze(ki);
|
||||
}
|
||||
|
||||
void monero_wallet_full::thaw_output(const std::string& key_image) {
|
||||
if (key_image.empty()) throw std::runtime_error("Must specify key image to thaw");
|
||||
crypto::key_image ki;
|
||||
if (!epee::string_tools::hex_to_pod(key_image, ki)) throw new std::runtime_error("failed to parse key imge");
|
||||
m_w2->thaw(ki);
|
||||
}
|
||||
|
||||
bool monero_wallet_full::is_output_frozen(const std::string& key_image) {
|
||||
if (key_image.empty()) throw std::runtime_error("Must specify key image to check if frozen");
|
||||
crypto::key_image ki;
|
||||
if (!epee::string_tools::hex_to_pod(key_image, ki)) throw new std::runtime_error("failed to parse key imge");
|
||||
return m_w2->frozen(ki);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<monero_tx_wallet>> monero_wallet_full::create_txs(const monero_tx_config& config) {
|
||||
MTRACE("monero_wallet_full::create_txs");
|
||||
//std::cout << "monero_tx_config: " << config.serialize() << std::endl;
|
||||
@@ -1815,7 +1861,8 @@ namespace monero {
|
||||
std::list<std::string> tx_hashes;
|
||||
std::list<std::string> tx_blobs;
|
||||
std::list<std::string> tx_metadatas;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) {
|
||||
std::list<key_image_list> input_key_images_list;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, err)) {
|
||||
throw std::runtime_error("need to handle error filling response!"); // TODO
|
||||
}
|
||||
|
||||
@@ -1828,6 +1875,7 @@ namespace monero {
|
||||
auto tx_weights_iter = tx_weights.begin();
|
||||
auto tx_blobs_iter = tx_blobs.begin();
|
||||
auto tx_metadatas_iter = tx_metadatas.begin();
|
||||
auto input_key_images_list_iter = input_key_images_list.begin();
|
||||
while (tx_fees_iter != tx_fees.end()) {
|
||||
|
||||
// init tx with outgoing transfer from filled values
|
||||
@@ -1843,6 +1891,16 @@ namespace monero {
|
||||
tx->m_outgoing_transfer = out_transfer;
|
||||
out_transfer->m_amount = *tx_amounts_iter;
|
||||
|
||||
// init inputs with key images
|
||||
std::list<std::string> input_key_images = (*input_key_images_list_iter).key_images;
|
||||
for (const std::string& input_key_image : input_key_images) {
|
||||
std::shared_ptr<monero_output_wallet> input = std::make_shared<monero_output_wallet>();
|
||||
input->m_tx = tx;
|
||||
tx->m_inputs.push_back(input);
|
||||
input->m_key_image = std::make_shared<monero_key_image>();
|
||||
input->m_key_image.get()->m_hex = input_key_image;
|
||||
}
|
||||
|
||||
// init other known fields
|
||||
tx->m_is_outgoing = true;
|
||||
tx->m_payment_id = config.m_payment_id;
|
||||
@@ -1869,6 +1927,7 @@ namespace monero {
|
||||
tx_hashes_iter++;
|
||||
tx_blobs_iter++;
|
||||
tx_metadatas_iter++;
|
||||
input_key_images_list_iter++;
|
||||
}
|
||||
|
||||
// build tx set
|
||||
@@ -2004,7 +2063,8 @@ namespace monero {
|
||||
std::list<std::string> tx_hashes;
|
||||
std::list<std::string> tx_blobs;
|
||||
std::list<std::string> tx_metadatas;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) {
|
||||
std::list<key_image_list> input_key_images_list;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, err)) {
|
||||
throw std::runtime_error("need to handle error filling response!"); // TODO
|
||||
}
|
||||
|
||||
@@ -2017,6 +2077,7 @@ namespace monero {
|
||||
auto tx_weights_iter = tx_weights.begin();
|
||||
auto tx_blobs_iter = tx_blobs.begin();
|
||||
auto tx_metadatas_iter = tx_metadatas.begin();
|
||||
auto input_key_images_list_iter = input_key_images_list.begin();
|
||||
while (tx_fees_iter != tx_fees.end()) {
|
||||
|
||||
// init tx with outgoing transfer from filled values
|
||||
@@ -2036,6 +2097,16 @@ namespace monero {
|
||||
std::shared_ptr<monero_destination> destination = std::make_shared<monero_destination>(destinations[0]->m_address.get(), out_transfer->m_amount.get());
|
||||
out_transfer->m_destinations.push_back(destination);
|
||||
|
||||
// init inputs with key images
|
||||
std::list<std::string> input_key_images = (*input_key_images_list_iter).key_images;
|
||||
for (const std::string& input_key_image : input_key_images) {
|
||||
std::shared_ptr<monero_output_wallet> input = std::make_shared<monero_output_wallet>();
|
||||
input->m_tx = tx;
|
||||
tx->m_inputs.push_back(input);
|
||||
input->m_key_image = std::make_shared<monero_key_image>();
|
||||
input->m_key_image.get()->m_hex = input_key_image;
|
||||
}
|
||||
|
||||
// init other known fields
|
||||
tx->m_payment_id = config.m_payment_id;
|
||||
tx->m_is_confirmed = false;
|
||||
@@ -2059,6 +2130,7 @@ namespace monero {
|
||||
tx_hashes_iter++;
|
||||
tx_blobs_iter++;
|
||||
tx_metadatas_iter++;
|
||||
input_key_images_list_iter++;
|
||||
}
|
||||
|
||||
// link tx std::set and return
|
||||
@@ -2127,7 +2199,8 @@ namespace monero {
|
||||
std::list<std::string> tx_hashes;
|
||||
std::list<std::string> tx_blobs;
|
||||
std::list<std::string> tx_metadatas;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, err)) {
|
||||
std::list<key_image_list> input_key_images_list;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, err)) {
|
||||
throw std::runtime_error("need to handle error filling response!"); // TODO: return err message
|
||||
}
|
||||
|
||||
@@ -2140,6 +2213,7 @@ namespace monero {
|
||||
auto tx_weights_iter = tx_weights.begin();
|
||||
auto tx_blobs_iter = tx_blobs.begin();
|
||||
auto tx_metadatas_iter = tx_metadatas.begin();
|
||||
auto input_key_images_list_iter = input_key_images_list.begin();
|
||||
while (tx_fees_iter != tx_fees.end()) {
|
||||
|
||||
// init tx with outgoing transfer from filled values
|
||||
@@ -2156,6 +2230,16 @@ namespace monero {
|
||||
tx->m_outgoing_transfer = out_transfer;
|
||||
out_transfer->m_amount = *tx_amounts_iter;
|
||||
|
||||
// init inputs with key images
|
||||
std::list<std::string> input_key_images = (*input_key_images_list_iter).key_images;
|
||||
for (const std::string& input_key_image : input_key_images) {
|
||||
std::shared_ptr<monero_output_wallet> input = std::make_shared<monero_output_wallet>();
|
||||
input->m_tx = tx;
|
||||
tx->m_inputs.push_back(input);
|
||||
input->m_key_image = std::make_shared<monero_key_image>();
|
||||
input->m_key_image.get()->m_hex = input_key_image;
|
||||
}
|
||||
|
||||
// init other known fields
|
||||
tx->m_payment_id = config.m_payment_id;
|
||||
tx->m_is_confirmed = false;
|
||||
@@ -2182,6 +2266,7 @@ namespace monero {
|
||||
tx_hashes_iter++;
|
||||
tx_blobs_iter++;
|
||||
tx_metadatas_iter++;
|
||||
input_key_images_list_iter++;
|
||||
}
|
||||
|
||||
// validate one transaction
|
||||
@@ -2220,8 +2305,9 @@ namespace monero {
|
||||
std::list<std::string> tx_hashes;
|
||||
std::list<std::string> tx_blobs;
|
||||
std::list<std::string> tx_metadatas;
|
||||
std::list<key_image_list> input_key_images_list;
|
||||
epee::json_rpc::error er;
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, er)) {
|
||||
if (!fill_response(m_w2.get(), ptx_vector, get_tx_keys, tx_keys, tx_amounts, tx_fees, tx_weights, multisig_tx_hex, unsigned_tx_hex, !relay, tx_hashes, get_tx_hex, tx_blobs, get_tx_metadata, tx_metadatas, input_key_images_list, er)) {
|
||||
throw std::runtime_error("need to handle error filling response!"); // TODO: return err message
|
||||
}
|
||||
|
||||
@@ -2234,6 +2320,7 @@ namespace monero {
|
||||
auto tx_weights_iter = tx_weights.begin();
|
||||
auto tx_blobs_iter = tx_blobs.begin();
|
||||
auto tx_metadatas_iter = tx_metadatas.begin();
|
||||
auto input_key_images_list_iter = input_key_images_list.begin();
|
||||
while (tx_fees_iter != tx_fees.end()) {
|
||||
|
||||
// init tx with outgoing transfer from filled values
|
||||
@@ -2250,6 +2337,16 @@ namespace monero {
|
||||
tx->m_outgoing_transfer = out_transfer;
|
||||
out_transfer->m_amount = *tx_amounts_iter;
|
||||
|
||||
// init inputs with key images
|
||||
std::list<std::string> input_key_images = (*input_key_images_list_iter).key_images;
|
||||
for (const std::string& input_key_image : input_key_images) {
|
||||
std::shared_ptr<monero_output_wallet> input = std::make_shared<monero_output_wallet>();
|
||||
input->m_tx = tx;
|
||||
tx->m_inputs.push_back(input);
|
||||
input->m_key_image = std::make_shared<monero_key_image>();
|
||||
input->m_key_image.get()->m_hex = input_key_image;
|
||||
}
|
||||
|
||||
// init other known fields
|
||||
tx->m_is_confirmed = false;
|
||||
tx->m_is_miner_tx = false;
|
||||
@@ -2271,13 +2368,11 @@ namespace monero {
|
||||
tx_hashes_iter++;
|
||||
tx_blobs_iter++;
|
||||
tx_metadatas_iter++;
|
||||
input_key_images_list_iter++;
|
||||
}
|
||||
|
||||
// throw exception if no dust to sweep (dust only exists pre-rct)
|
||||
if (txs.empty() && multisig_tx_hex.empty() && unsigned_tx_hex.empty()) throw std::runtime_error("No dust to sweep");
|
||||
|
||||
// link tx set
|
||||
std::shared_ptr<monero_tx_set> tx_set;
|
||||
std::shared_ptr<monero_tx_set> tx_set = std::make_shared<monero_tx_set>();
|
||||
tx_set->m_txs = txs;
|
||||
for (int i = 0; i < txs.size(); i++) txs[i]->m_tx_set = tx_set;
|
||||
if (!multisig_tx_hex.empty()) tx_set->m_multisig_tx_hex = multisig_tx_hex;
|
||||
@@ -3333,7 +3428,7 @@ namespace monero {
|
||||
std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>> payments;
|
||||
m_w2->get_unconfirmed_payments(payments, account_index, subaddress_indices);
|
||||
for (std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
|
||||
if (!tx_query->m_hashes.empty() && std::find(tx_query->m_hashes.begin(), tx_query->m_hashes.end(), epee::string_tools::pod_to_hex(i->second.m_pd.m_tx_hash)) == tx_query->m_hashes.end()); // skip if hash filtered
|
||||
if (!tx_query->m_hashes.empty() && std::find(tx_query->m_hashes.begin(), tx_query->m_hashes.end(), epee::string_tools::pod_to_hex(i->second.m_pd.m_tx_hash)) == tx_query->m_hashes.end()) continue; // skip if hash filtered
|
||||
std::shared_ptr<monero_tx_wallet> tx = build_tx_with_incoming_transfer_unconfirmed(*m_w2, height, i->first, i->second);
|
||||
merge_tx(tx, tx_map, block_map);
|
||||
}
|
||||
|
||||
@@ -228,6 +228,9 @@ namespace monero {
|
||||
int import_outputs(const std::string& outputs_hex) override;
|
||||
std::vector<std::shared_ptr<monero_key_image>> export_key_images(bool all = false) const override;
|
||||
std::shared_ptr<monero_key_image_import_result> import_key_images(const std::vector<std::shared_ptr<monero_key_image>>& key_images) override;
|
||||
void freeze_output(const std::string& key_image) override;
|
||||
void thaw_output(const std::string& key_image) override;
|
||||
bool is_output_frozen(const std::string& key_image) override;
|
||||
std::vector<std::shared_ptr<monero_tx_wallet>> create_txs(const monero_tx_config& config) override;
|
||||
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_unlocked(const monero_tx_config& config) override;
|
||||
std::shared_ptr<monero_tx_wallet> sweep_output(const monero_tx_config& config) override;
|
||||
|
||||
@@ -398,6 +398,11 @@ namespace monero {
|
||||
monero_transfer_query::from_property_tree(it->second, tx_query->m_transfer_query.get());
|
||||
tx_query->m_transfer_query.get()->m_tx_query = tx_query;
|
||||
}
|
||||
else if (key == std::string("inputQuery")) {
|
||||
tx_query->m_input_query = std::make_shared<monero_output_query>();
|
||||
monero_output_query::from_property_tree(it->second, tx_query->m_input_query.get());
|
||||
tx_query->m_input_query.get()->m_tx_query = tx_query;
|
||||
}
|
||||
else if (key == std::string("outputQuery")) {
|
||||
tx_query->m_output_query = std::make_shared<monero_output_query>();
|
||||
monero_output_query::from_property_tree(it->second, tx_query->m_output_query.get());
|
||||
@@ -452,6 +457,10 @@ namespace monero {
|
||||
tgt->m_transfer_query = src->m_transfer_query.get()->copy(src->m_transfer_query.get(), std::make_shared<monero_transfer_query>());
|
||||
tgt->m_transfer_query.get()->m_tx_query = tgt;
|
||||
}
|
||||
if (src->m_input_query != boost::none) {
|
||||
tgt->m_input_query = src->m_input_query.get()->copy(src->m_input_query.get(), std::make_shared<monero_output_query>());
|
||||
tgt->m_input_query.get()->m_tx_query = tgt;
|
||||
}
|
||||
if (src->m_output_query != boost::none) {
|
||||
tgt->m_output_query = src->m_output_query.get()->copy(src->m_output_query.get(), std::make_shared<monero_output_query>());
|
||||
tgt->m_output_query.get()->m_tx_query = tgt;
|
||||
@@ -510,6 +519,20 @@ namespace monero {
|
||||
if (!match_found) return false;
|
||||
}
|
||||
|
||||
// at least one input must meet input query if defined
|
||||
if (m_input_query != boost::none) {
|
||||
if (tx->m_inputs.empty()) return false;
|
||||
bool match_found = false;
|
||||
for (const std::shared_ptr<monero_output>& input : tx->m_inputs) {
|
||||
std::shared_ptr<monero_output_wallet> vin_wallet = std::static_pointer_cast<monero_output_wallet>(input);
|
||||
if (m_input_query.get()->meets_criteria(vin_wallet.get(), false)) {
|
||||
match_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match_found) return false;
|
||||
}
|
||||
|
||||
// at least one output must meet output query if defined
|
||||
if (m_output_query != boost::none) {
|
||||
if (tx->m_outputs.empty()) return false;
|
||||
@@ -1052,10 +1075,12 @@ namespace monero {
|
||||
// get tx query
|
||||
std::shared_ptr<monero_tx_query> tx_query = std::static_pointer_cast<monero_tx_query>(block->m_txs[0]);
|
||||
|
||||
// get / create input query
|
||||
std::shared_ptr<monero_output_query> input_query = tx_query->m_input_query == boost::none ? std::make_shared<monero_output_query>() : *tx_query->m_input_query;
|
||||
input_query->m_tx_query = tx_query;
|
||||
|
||||
// get / create output query
|
||||
std::shared_ptr<monero_output_query> output_query = tx_query->m_output_query == boost::none ? std::make_shared<monero_output_query>() : *tx_query->m_output_query;
|
||||
|
||||
// set output query's tx query
|
||||
output_query->m_tx_query = tx_query;
|
||||
|
||||
// return deserialized query
|
||||
@@ -1093,6 +1118,7 @@ namespace monero {
|
||||
if (m_subaddress_index != boost::none && (output->m_subaddress_index == boost::none || *m_subaddress_index != *output->m_subaddress_index)) return false;
|
||||
if (m_amount != boost::none && (output->m_amount == boost::none || *m_amount != *output->m_amount)) return false;
|
||||
if (m_is_spent != boost::none && (output->m_is_spent == boost::none || *m_is_spent != *output->m_is_spent)) return false;
|
||||
if (m_is_frozen != boost::none && (output->m_is_frozen == boost::none || *m_is_frozen != *output->m_is_frozen)) return false;
|
||||
|
||||
// filter on output key image
|
||||
if (m_key_image != boost::none) {
|
||||
|
||||
@@ -286,6 +286,7 @@ namespace monero {
|
||||
boost::optional<uint64_t> m_max_height;
|
||||
boost::optional<uint64_t> m_include_outputs;
|
||||
boost::optional<std::shared_ptr<monero_transfer_query>> m_transfer_query;
|
||||
boost::optional<std::shared_ptr<monero_output_query>> m_input_query;
|
||||
boost::optional<std::shared_ptr<monero_output_query>> m_output_query;
|
||||
|
||||
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const;
|
||||
|
||||
Reference in New Issue
Block a user