mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-17 15:21:30 +02:00
compiling with send convenience methods
This commit is contained in:
@@ -1694,6 +1694,76 @@ namespace monero {
|
||||
return result;
|
||||
}
|
||||
|
||||
shared_ptr<monero_tx_wallet> monero_wallet::create_tx(uint32_t account_index, String address, uint64_t amount) {
|
||||
throw new runtime_error("create_tx not implemented");
|
||||
}
|
||||
|
||||
shared_ptr<monero_tx_wallet> monero_wallet::create_tx(int account_index, String address, uint64_t amount, monero_send_priority priority) {
|
||||
throw new runtime_error("create_tx not implemented");
|
||||
}
|
||||
|
||||
shared_ptr<monero_tx_wallet> monero_wallet::create_tx(const monero_send_request& request) {
|
||||
throw new runtime_error("create_tx not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet::relay_tx(const string& tx_metadata) {
|
||||
throw new runtime_error("relay_tx not implemented");
|
||||
}
|
||||
|
||||
string monero_wallet::relay_tx(const monero_tx_wallet& tx) {
|
||||
throw new runtime_error("relay_tx not implemented");
|
||||
}
|
||||
|
||||
vector<string> monero_wallet::relay_txs(const vector<string>& tx_metadatas) {
|
||||
MTRACE("relay_txs()");
|
||||
|
||||
// relay each metadata as a tx
|
||||
vector<string> m_tx_ids;
|
||||
for (const auto& txMetadata : tx_metadatas) {
|
||||
|
||||
// parse tx metadata hex
|
||||
cryptonote::blobdata blob;
|
||||
if (!epee::string_tools::parse_hexstr_to_binbuff(txMetadata, blob)) {
|
||||
throw runtime_error("Failed to parse hex.");
|
||||
}
|
||||
|
||||
// deserialize tx
|
||||
tools::wallet2::pending_tx ptx;
|
||||
try {
|
||||
std::istringstream iss(blob);
|
||||
boost::archive::portable_binary_iarchive ar(iss);
|
||||
ar >> ptx;
|
||||
} catch (...) {
|
||||
throw runtime_error("Failed to parse tx metadata.");
|
||||
}
|
||||
|
||||
// commit tx
|
||||
try {
|
||||
m_w2->commit_tx(ptx);
|
||||
} catch (const std::exception& e) {
|
||||
throw runtime_error("Failed to commit tx.");
|
||||
}
|
||||
|
||||
// collect resulting id
|
||||
m_tx_ids.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx)));
|
||||
}
|
||||
|
||||
// return relayed tx ids
|
||||
return m_tx_ids;
|
||||
}
|
||||
|
||||
vector<string> monero_wallet::relay_txs(const vector<monero_tx_wallet>& txs) {
|
||||
throw new runtime_error("relay_txs not implemented");
|
||||
}
|
||||
|
||||
shared_ptr<monero_tx_wallet> monero_wallet::send(uint32_t account_index, string address, uint64_t amount) {
|
||||
throw new runtime_error("send not implemented");
|
||||
}
|
||||
|
||||
shared_ptr<monero_tx_wallet> monero_wallet::send(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority) {
|
||||
throw new runtime_error("send not implemented");
|
||||
}
|
||||
|
||||
vector<shared_ptr<monero_tx_wallet>> monero_wallet::send_split(const monero_send_request& request) {
|
||||
MTRACE("monero_wallet::send_split(request)");
|
||||
MTRACE("monero_send_request: " << request.serialize());
|
||||
@@ -1992,44 +2062,6 @@ namespace monero {
|
||||
return txs;
|
||||
}
|
||||
|
||||
vector<string> monero_wallet::relay_txs(const vector<string>& tx_metadatas) {
|
||||
MTRACE("relay_txs()");
|
||||
|
||||
// relay each metadata as a tx
|
||||
vector<string> m_tx_ids;
|
||||
for (const auto& txMetadata : tx_metadatas) {
|
||||
|
||||
// parse tx metadata hex
|
||||
cryptonote::blobdata blob;
|
||||
if (!epee::string_tools::parse_hexstr_to_binbuff(txMetadata, blob)) {
|
||||
throw runtime_error("Failed to parse hex.");
|
||||
}
|
||||
|
||||
// deserialize tx
|
||||
tools::wallet2::pending_tx ptx;
|
||||
try {
|
||||
std::istringstream iss(blob);
|
||||
boost::archive::portable_binary_iarchive ar(iss);
|
||||
ar >> ptx;
|
||||
} catch (...) {
|
||||
throw runtime_error("Failed to parse tx metadata.");
|
||||
}
|
||||
|
||||
// commit tx
|
||||
try {
|
||||
m_w2->commit_tx(ptx);
|
||||
} catch (const std::exception& e) {
|
||||
throw runtime_error("Failed to commit tx.");
|
||||
}
|
||||
|
||||
// collect resulting id
|
||||
m_tx_ids.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx)));
|
||||
}
|
||||
|
||||
// return relayed tx ids
|
||||
return m_tx_ids;
|
||||
}
|
||||
|
||||
string monero_wallet::get_tx_note(const string& tx_id) const {
|
||||
MTRACE("monero_wallet::get_tx_note()");
|
||||
cryptonote::blobdata tx_blob;
|
||||
|
||||
+87
-16
@@ -745,6 +745,93 @@ namespace monero {
|
||||
// */
|
||||
// public List<monero_key_image> getNewKeyImagesFromLastImport();
|
||||
|
||||
/**
|
||||
* Create a transaction to transfers funds from this wallet to a destination address.
|
||||
* The transaction may be relayed later.
|
||||
*
|
||||
* @param accountIndex is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @return the resulting transaction
|
||||
*/
|
||||
shared_ptr<monero_tx_wallet> create_tx(uint32_t account_index, string address, uint64_t amount);
|
||||
|
||||
/**
|
||||
* Create a transaction to transfers funds from this wallet to a destination address.
|
||||
* The transaction may be relayed later.
|
||||
*
|
||||
* @param accountIndex is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @param priority is the send priority (default normal)
|
||||
* @return the resulting transaction
|
||||
*/
|
||||
shared_ptr<monero_tx_wallet> create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority);
|
||||
|
||||
/**
|
||||
* Create a transaction to transfer funds from this wallet according to the
|
||||
* given request. The transaction may be relayed later.
|
||||
*
|
||||
* @param request configures the transaction to create
|
||||
* @return the created transaction
|
||||
*/
|
||||
shared_ptr<monero_tx_wallet> create_tx(const monero_send_request& request);
|
||||
|
||||
/**
|
||||
* Relay a transaction previously created without relaying.
|
||||
*
|
||||
* @param txMetadata is transaction metadata previously created without relaying
|
||||
* @return string is the id of the relayed tx
|
||||
*/
|
||||
string relay_tx(const string& tx_metadata);
|
||||
|
||||
/**
|
||||
* Relay a previously created transaction.
|
||||
*
|
||||
* @param tx is the transaction to relay
|
||||
* @return the id of the relayed tx
|
||||
*/
|
||||
string relay_tx(const monero_tx_wallet& tx);
|
||||
|
||||
/**
|
||||
* Relay transactions previously created without relaying.
|
||||
*
|
||||
* @param tx_metadatas are transaction metadata previously created without relaying
|
||||
* @return the ids of the relayed txs
|
||||
*/
|
||||
vector<string> relay_txs(const vector<string>& tx_metadatas);
|
||||
|
||||
/**
|
||||
* Relay previously created transactions.
|
||||
*
|
||||
* @param txs are the transactions to relay
|
||||
* @return the ids of the relayed txs
|
||||
*/
|
||||
vector<string> relay_txs(const vector<monero_tx_wallet>& txs);
|
||||
|
||||
/**
|
||||
* Create and relay a transaction to transfers funds from this wallet to
|
||||
* a destination address.
|
||||
*
|
||||
* @param account_index is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @return the resulting transaction
|
||||
*/
|
||||
shared_ptr<monero_tx_wallet> send(uint32_t account_index, string address, uint64_t amount);
|
||||
|
||||
/**
|
||||
* Create and relay a transaction to transfers funds from this wallet to
|
||||
* a destination address.
|
||||
*
|
||||
* @param account_index is the index of the account to withdraw funds from
|
||||
* @param address is the destination address to send funds to
|
||||
* @param amount is the amount being sent
|
||||
* @param priority is the send priority (default normal)
|
||||
* @return the resulting transaction
|
||||
*/
|
||||
shared_ptr<monero_tx_wallet> send(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority);
|
||||
|
||||
/**
|
||||
* Create one or more transactions which transfer funds from this wallet to
|
||||
* one or more destinations depending on the given configuration.
|
||||
@@ -888,22 +975,6 @@ namespace monero {
|
||||
* @return the resulting transactions from sweeping dust
|
||||
*/
|
||||
vector<shared_ptr<monero_tx_wallet>> sweep_dust(bool do_not_relay = false);
|
||||
//
|
||||
// /**
|
||||
// * Relay a transaction previously created without relaying.
|
||||
// *
|
||||
// * @param txMetadata is transaction metadata previously created without relaying
|
||||
// * @return string is the id of the relayed tx
|
||||
// */
|
||||
// public string relayTx(string txMetadata);
|
||||
|
||||
/**
|
||||
* Relay transactions previously created without relaying.
|
||||
*
|
||||
* @param tx_metadatas are transaction metadata previously created without relaying
|
||||
* @return the ids of the relayed txs
|
||||
*/
|
||||
vector<string> relay_txs(const vector<string>& tx_metadatas);
|
||||
|
||||
/**
|
||||
* Get a transaction note.
|
||||
|
||||
@@ -83,10 +83,9 @@ int main(int argc, const char* argv[]) {
|
||||
} my_listener;
|
||||
wallet_random->set_listener(my_listener);
|
||||
|
||||
// TODO: define wallet send convenience methods
|
||||
// // send funds from the restored wallet to the random wallet
|
||||
// monero_tx_wallet sent_tx = wallet_restored->send(0, wallet_random->get_address(1, 0), 50000);
|
||||
// boolean in_pool = sent_tx.in_tx_pool(); // true
|
||||
// send funds from the restored wallet to the random wallet
|
||||
shared_ptr<monero_tx_wallet> sent_tx = wallet_restored->send(0, wallet_random->get_address(1, 0), 50000);
|
||||
bool in_pool = sent_tx->m_in_tx_pool.get(); // true
|
||||
|
||||
// create a request to send funds to multiple destinations in the random wallet
|
||||
monero_send_request send_request = monero_send_request();
|
||||
@@ -100,9 +99,8 @@ int main(int argc, const char* argv[]) {
|
||||
// destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(2, 0), 50000));
|
||||
send_request.m_destinations = destinations;
|
||||
|
||||
// TODO: define wallet send convenience methods
|
||||
// // create the transaction, confirm with the user, and relay to the network
|
||||
// shared_ptr<monero_tx_wallet> created_tx = wallet_restored->create_tx(send_request);
|
||||
// uint64_t fee = created_tx->fee.get(); // "Are you sure you want to send ...?"
|
||||
// wallet_restored->relay_tx(created_tx); // submit the transaction to the Monero network which will notify the recipient wallet
|
||||
// create the transaction, confirm with the user, and relay to the network
|
||||
shared_ptr<monero_tx_wallet> created_tx = wallet_restored->create_tx(send_request);
|
||||
uint64_t fee = created_tx->m_fee.get(); // "Are you sure you want to send ...?"
|
||||
wallet_restored->relay_tx(*created_tx); // submit the transaction to the Monero network which will notify the recipient wallet
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user