mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-17 15:21:30 +02:00
sample code completing successfully;
implement wait_for_next_block() without returning height; fix query make_shared copy
This commit is contained in:
+14
-8
@@ -5,6 +5,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool OUTPUT_RECEIVED = false;
|
||||
|
||||
/**
|
||||
* This code introduces the API.
|
||||
*
|
||||
@@ -13,6 +15,10 @@ using namespace std;
|
||||
*/
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
// // configure logging
|
||||
// mlog_configure("log_cpp_sample_code.txt", true);
|
||||
// mlog_set_log_level(1);
|
||||
|
||||
// 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";
|
||||
monero_wallet* wallet_restored = monero_wallet::create_wallet_from_mnemonic(
|
||||
@@ -43,7 +49,7 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
// query a transaction by id
|
||||
monero_tx_query tx_query;
|
||||
tx_query.m_id = "3276252c5a545b90c8e147fcde45d3e1917726470a8f7d4c8977b527a44dfd15";
|
||||
tx_query.m_id = "314a0f1375db31cea4dac4e0a51514a6282b43792269b3660166d4d2b46437ca";
|
||||
shared_ptr<monero_tx_wallet> tx = wallet_restored->get_txs(tx_query)[0];
|
||||
for (const shared_ptr<monero_incoming_transfer> in_transfer : tx->m_incoming_transfers) {
|
||||
uint64_t in_amount = in_transfer->m_amount.get();
|
||||
@@ -71,6 +77,7 @@ int main(int argc, const char* argv[]) {
|
||||
);
|
||||
|
||||
// continuously synchronize the wallet
|
||||
wallet_random->sync(); // TODO: is this necessary here to be synced? random wallet should be synced if created with rpc connection
|
||||
wallet_random->start_syncing();
|
||||
|
||||
// get wallet info
|
||||
@@ -83,9 +90,10 @@ int main(int argc, const char* argv[]) {
|
||||
struct : monero_wallet_listener {
|
||||
void on_output_received(const monero_output_wallet& output) {
|
||||
cout << "Wallet received funds!" << endl;
|
||||
string tx_id = output.m_tx->m_id.get();
|
||||
int account_index = output.m_account_index.get();
|
||||
int subaddress_index = output.m_subaddress_index.get();
|
||||
shared_ptr<monero_key_image> key_image = output.m_key_image.get();
|
||||
OUTPUT_RECEIVED = true;
|
||||
}
|
||||
} my_listener;
|
||||
wallet_random->add_listener(my_listener);
|
||||
@@ -101,9 +109,7 @@ int main(int argc, const char* argv[]) {
|
||||
wallet_restored->start_mining(num_threads, is_background, ignore_battery);
|
||||
|
||||
// wait for the next block to be added to the chain
|
||||
// uint64_t next_height = wallet_random->wait_for_next_block();
|
||||
// MoneroBlockHeader nextBlockHeader = daemon.getNextBlockHeader();
|
||||
// long nextNumTxs = nextBlockHeader.getNumTxs();
|
||||
uint64_t next_height = wallet_random->wait_for_next_block();
|
||||
|
||||
// stop mining
|
||||
wallet_restored->stop_mining();
|
||||
@@ -125,7 +131,7 @@ int main(int argc, const char* argv[]) {
|
||||
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
|
||||
|
||||
// random wallet will receive notification of incoming output after a moment
|
||||
//TimeUnit.SECONDS.sleep(10);
|
||||
//assertTrue(JNI_OUTPUT_RECEIVED);
|
||||
// random wallet has received notification of incoming output
|
||||
if (OUTPUT_RECEIVED) cout << "Sample code completed successfully" << endl;
|
||||
else throw runtime_error("Output should have been received");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user