find_txs_in_mempool method moved to TxSearch class

pull/4/head
moneroexamples 7 years ago
parent 6462ca4fba
commit 0aaf3580f6

@ -1,6 +1,6 @@
var config = {
apiUrl: "http://127.0.0.1:1984/",
testnet: false,
testnet: true,
coinUnitPlaces: 12,
txMinConfirms: 10,
coinSymbol: 'XMR',

@ -621,8 +621,28 @@ CurrentBlockchainStatus::get_xmr_address_viewkey(
return true;
};
bool
CurrentBlockchainStatus::find_txs_in_mempool(
const string& address_str,
json& transactions)
{
std::lock_guard<std::mutex> lck (searching_threads_map_mtx);
if (searching_threads.count(address_str) == 0)
{
// thread does not exist
cout << "thread for " << address_str << " does not exist" << endl;
return false;
}
transactions = searching_threads[address_str].get()
->find_txs_in_mempool(mempool_txs);
return true;
};
bool
CurrentBlockchainStatus::set_new_searched_blk_no(const string& address, uint64_t new_value)
{
std::lock_guard<std::mutex> lck (searching_threads_map_mtx);

@ -156,6 +156,9 @@ struct CurrentBlockchainStatus
get_xmr_address_viewkey(const string& address_str,
account_public_address& address,
secret_key& viewkey);
static bool
find_txs_in_mempool(const string& address_str,
json& transactions);
static bool
set_new_searched_blk_no(const string& address,

@ -451,11 +451,62 @@ TxSearch::populate_known_outputs()
{
known_outputs_keys.push_back(make_pair(out.out_pub_key, out.amount));
}
}
}
pair<account_public_address, secret_key>
json
TxSearch::find_txs_in_mempool(vector<transaction> mempool_txs)
{
json j_transactions = json::array();
uint64_t current_height = CurrentBlockchainStatus::get_current_blockchain_height();
for (const transaction& tx: mempool_txs)
{
// Class that is resposnible for idenficitaction of our outputs
// and inputs in a given tx.
OutputInputIdentification oi_identification {&address, &viewkey, &tx};
// FIRSt step. to search for the incoming xmr, we use address, viewkey and
// outputs public key.
oi_identification.identify_outputs();
//vector<uint64_t> amount_specific_indices;
// if we identified some outputs as ours,
// save them into json to be returned.
if (!oi_identification.identified_outputs.empty())
{
json j_tx;
j_tx["id"] = 0;
j_tx["hash"] = oi_identification.tx_hash_str;
j_tx["timestamp"] = "";
j_tx["total_received"] = oi_identification.total_received;
j_tx["total_sent"] = 0;
j_tx["unlock_time"] = 0;
j_tx["height"] = current_height; // put large value of height,
// just to indicate that we dont have
// height and that in frontend it will
// appear us unconfirmed.
j_tx["payment_id"] = "";
j_tx["coinbase"] = false;
j_tx["mixin"] = get_mixin_no(tx) - 1;
j_transactions.push_back(j_tx);
}
} // for (const transaction& tx: txs_to_check)
return j_transactions;
}
pair<account_public_address, secret_key>
TxSearch::get_xmr_address_viewkey() const
{
return make_pair(address, viewkey);

@ -91,6 +91,34 @@ public:
void
populate_known_outputs();
/**
* Search for our txs in the mempool
*
* The method searches for our txs (outputs and inputs)
* in the mempool. It does basically same what search method
* The difference is that search method searches in a thread
* in a blockchain. It does not scan for tx in mempool. This is because
* it writes what it finds into database for permament storage.
* However txs in mempool are not permament. Also since we want to
* give the end user quick update on incoming/outging tx, this method
* will be executed whenever frontend wants. By default it is every
* 10 seconds. TxSearch class is timed independetly of the frontend.
* Also since we dont write here anything to the database, we
* return a json that will be appended to json produced by get_address_tx
* and similar function. The outputs here cant be spent anyway. This is
* only for end user information. The txs found here will be written
* to database later on by TxSearch thread when they will be added
* to the blockchain.
*
* we pass mempool_txs by copy because we want copy of mempool txs.
* to avoid worrying about synchronizing threads
*
* @return json
*/
json
find_txs_in_mempool(vector<transaction> mempool_txs);
pair<account_public_address, secret_key>
get_xmr_address_viewkey() const;

@ -231,14 +231,11 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B
// append txs found in mempool to the json returned
account_public_address address_parsed;
secret_key viewkey_parsed;
json j_mempool_tx;
if (CurrentBlockchainStatus::get_xmr_address_viewkey(
xmr_address, address_parsed, viewkey_parsed))
if (CurrentBlockchainStatus::find_txs_in_mempool(
xmr_address, j_mempool_tx))
{
json j_mempool_tx = find_txs_in_mempool(&address_parsed, &viewkey_parsed);
if(!j_mempool_tx.empty())
{
uint64_t total_received_mempool {0};
@ -779,59 +776,6 @@ YourMoneroRequests::get_current_blockchain_height()
}
json
YourMoneroRequests::find_txs_in_mempool(
const account_public_address* address,
const secret_key* viewkey)
{
vector<transaction> txs_to_check = CurrentBlockchainStatus::get_mempool_txs();
json j_transactions = json::array();
uint64_t current_height = CurrentBlockchainStatus::get_current_blockchain_height();
for (const transaction& tx: txs_to_check)
{
// Class that is resposnible for idenficitaction of our outputs
// and inputs in a given tx.
OutputInputIdentification oi_identification {address, viewkey, &tx};
// FIRSt step. to search for the incoming xmr, we use address, viewkey and
// outputs public key.
oi_identification.identify_outputs();
//vector<uint64_t> amount_specific_indices;
// if we identified some outputs as ours,
// save them into json to be returned.
if (!oi_identification.identified_outputs.empty())
{
json j_tx;
j_tx["id"] = 0;
j_tx["hash"] = oi_identification.tx_hash_str;
j_tx["timestamp"] = get_current_time();
j_tx["total_received"] = oi_identification.total_received;
j_tx["total_sent"] = 0;
j_tx["unlock_time"] = 0;
j_tx["height"] = current_height; // put large value of height,
// just to indicate that we dont have
// height and that in frontend it will
// appear us unconfirmed.
j_tx["payment_id"] = "";
j_tx["coinbase"] = false;
j_tx["mixin"] = get_mixin_no(tx) - 1;
j_transactions.push_back(j_tx);
}
} // for (const transaction& tx: txs_to_check)
return j_transactions;
}
// define static variables
bool YourMoneroRequests::show_logs = false;
}

@ -107,32 +107,6 @@ public:
inline uint64_t
get_current_blockchain_height();
private:
/**
* Search for our txs in the mempool
*
* The method searches for our txs (outputs and inputs)
* in the mempool. It does basically same what TxSearch class is
* doing. The difference is that TxSearch class searches in a thread
* in a blockchain. It does not scan for tx in mempool. This is because
* TxSearch writes what it finds into database for permament storage.
* However txs in mempool are not permament. Also since we want to
* give the end user quick update on incoming/outging tx, this method
* will be executed whenever frontend wants. By default it is every
* 10 seconds. TxSearch class is timed independetly of the frontend.
* Also since we dont write here anything to the database, we
* return a json that will be appended to json produced by get_address_tx
* and similar function. The outputs here cant be spent anyway. This is
* only for end user information. The txs found here will be written
* to database later on by TxSearch thread when they will be added
* to the blockchain.
*
* @return json
*/
json
find_txs_in_mempool(const account_public_address* address,
const secret_key* viewkey);
};

Loading…
Cancel
Save