outputs looking mempool refactored

pull/4/head
moneroexamples 7 years ago
parent 08c0d123a0
commit 09d6f3a60e

@ -151,8 +151,14 @@ thinwalletCtrls.controller('AccountCtrl', function($scope, $rootScope, $http, $q
transactions[i].approx_float_amount = parseFloat(cnUtil.formatMoney(transactions[i].amount));
transactions[i].timestamp = new Date(transactions[i].timestamp);
}
transactions.sort(function(a, b) {
return b.id - a.id;
transactions.sort(function(a, b)
{
// return b.id - a.id; // dont sort by id, better by timestamp
var t1 = b.timestamp;
var t2 = a.timestamp;
return ((t1 < t2) ? -1 : ((t1 > t2) ? 1 : 0));
});
$scope.transactions = transactions;
$scope.total_received = new JSBigInt(data.total_received || 0);

@ -26,7 +26,7 @@ std::thread CurrentBlockchainStatus::m_thread;
uint64_t CurrentBlockchainStatus::refresh_block_status_every_seconds{60};
xmreg::MicroCore CurrentBlockchainStatus::mcore;
cryptonote::Blockchain *CurrentBlockchainStatus::core_storage;
vector<transaction> CurrentBlockchainStatus::mempool_txs;
vector<pair<uint64_t, transaction>> CurrentBlockchainStatus::mempool_txs;
string CurrentBlockchainStatus::import_payment_address;
string CurrentBlockchainStatus::import_payment_viewkey;
uint64_t CurrentBlockchainStatus::import_fee {10000000000}; // 0.01 xmr
@ -339,6 +339,11 @@ CurrentBlockchainStatus::read_mempool()
// get transaction info of the tx in the mempool
tx_info _tx_info = mempool_tx_info.at(i);
if (_tx_info.do_not_relay == true)
{
continue;
}
crypto::hash mem_tx_hash = null_hash;
if (hex_to_pod(_tx_info.id_hash, mem_tx_hash))
@ -360,7 +365,7 @@ CurrentBlockchainStatus::read_mempool()
return false;
}
mempool_txs.push_back(tx);
mempool_txs.emplace_back(_tx_info.receive_time, tx);
} // if (hex_to_pod(_tx_info.id_hash, mem_tx_hash))
@ -369,7 +374,7 @@ CurrentBlockchainStatus::read_mempool()
return true;
}
vector<transaction>
vector<pair<uint64_t, transaction>>
CurrentBlockchainStatus::get_mempool_txs()
{
std::lock_guard<std::mutex> lck (getting_mempool_txs);
@ -383,10 +388,17 @@ CurrentBlockchainStatus::search_if_payment_made(
string& tx_hash_with_payment)
{
vector<transaction> txs_to_check = get_mempool_txs();
vector<pair<uint64_t, transaction>> mempool_transactions = get_mempool_txs();
uint64_t current_blockchain_height = current_height;
vector<transaction> txs_to_check;
for (auto& mtx: mempool_transactions)
{
txs_to_check.push_back(mtx.second);
}
// apend txs in last to blocks into the txs_to_check vector
for (uint64_t blk_i = current_blockchain_height - 10;
blk_i <= current_blockchain_height;
@ -408,6 +420,8 @@ CurrentBlockchainStatus::search_if_payment_made(
return false;
}
// combine mempool txs and txs from given number of
// last blocks
txs_to_check.insert(txs_to_check.end(), blk_txs.begin(), blk_txs.end());
}

@ -59,7 +59,8 @@ struct CurrentBlockchainStatus
// vector of mempool transactions that all threads
// can refer to
static vector<transaction> mempool_txs;
// <recieved_time, transaction>
static vector<pair<uint64_t, transaction>> mempool_txs;
// map that will keep track of search threads. In the
// map, key is address to which a running thread belongs to.
@ -127,7 +128,7 @@ struct CurrentBlockchainStatus
static bool
read_mempool();
static vector<transaction>
static vector<pair<uint64_t, transaction>>
get_mempool_txs();
static bool

@ -12,7 +12,7 @@ OutputInputIdentification::OutputInputIdentification(
const account_public_address* _a,
const secret_key* _v,
const transaction* _tx)
: total_received {0}
: total_received {0}, mixin_no {0}
{
address = _a;
viewkey = _v;
@ -36,6 +36,12 @@ OutputInputIdentification::OutputInputIdentification(
throw OutputInputIdentificationException("Cant get derived key for a tx");
}
if (!tx_is_coinbase)
{
mixin_no = get_mixin_no(*tx) - 1;
}
}
void
@ -46,6 +52,8 @@ OutputInputIdentification::identify_outputs()
outputs = get_ouputs_tuple(*tx);
for (auto& out: outputs)
{
txout_to_key txout_k = std::get<0>(out);
@ -84,16 +92,16 @@ OutputInputIdentification::identify_outputs()
// for ringct, except coinbase, it will be 0
uint64_t rct_amount_val = amount;
rtc_outpk = pod_to_hex(tx->rct_signatures.outPk[output_idx_in_tx].mask);
rtc_mask = pod_to_hex(tx->rct_signatures.ecdhInfo[output_idx_in_tx].mask);
rtc_amount = pod_to_hex(tx->rct_signatures.ecdhInfo[output_idx_in_tx].amount);
// cointbase txs have amounts in plain sight.
// so use amount from ringct, only for non-coinbase txs
if (!tx_is_coinbase)
{
bool r;
rtc_outpk = pod_to_hex(tx->rct_signatures.outPk[output_idx_in_tx].mask);
rtc_mask = pod_to_hex(tx->rct_signatures.ecdhInfo[output_idx_in_tx].mask);
rtc_amount = pod_to_hex(tx->rct_signatures.ecdhInfo[output_idx_in_tx].amount);
rct::key mask = tx->rct_signatures.ecdhInfo[output_idx_in_tx].mask;
r = decode_ringct(tx->rct_signatures,

@ -79,6 +79,8 @@ public:
bool tx_is_coinbase;
uint64_t mixin_no;
// for each output, in a tx, check if it belongs
// to the given account of specific address and viewkey

@ -194,13 +194,14 @@ TxSearch::search()
tx_data.account_id = acc->id;
tx_data.total_received = oi_identification.total_received;
tx_data.total_sent = 0; // at this stage we don't have any
// info about spendings
tx_data.unlock_time = 0;
// info about spendings
tx_data.unlock_time = 0; // this seems to be not used at all
// in frontend
tx_data.height = searched_blk_no;
tx_data.coinbase = oi_identification.tx_is_coinbase;
tx_data.spendable = is_spendable;
tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx);
tx_data.mixin = get_mixin_no(tx) - 1;
tx_data.mixin = oi_identification.mixin_no;
tx_data.timestamp = blk_timestamp_mysql_format;
@ -456,14 +457,20 @@ TxSearch::populate_known_outputs()
json
TxSearch::find_txs_in_mempool(vector<transaction> mempool_txs)
TxSearch::find_txs_in_mempool(
vector<pair<uint64_t, transaction>> mempool_txs)
{
json j_transactions = json::array();
uint64_t current_height = CurrentBlockchainStatus::get_current_blockchain_height();
for (const transaction& tx: mempool_txs)
for (const pair<uint64_t, transaction>& mtx: mempool_txs)
{
uint64_t recieve_time = mtx.first;
const transaction& tx = mtx.second;
// Class that is resposnible for idenficitaction of our outputs
// and inputs in a given tx.
OutputInputIdentification oi_identification {&address, &viewkey, &tx};
@ -480,19 +487,20 @@ TxSearch::find_txs_in_mempool(vector<transaction> mempool_txs)
{
json j_tx;
j_tx["id"] = 0;
j_tx["id"] = 0; // dont have any database id for tx in mempool
j_tx["hash"] = oi_identification.tx_hash_str;
j_tx["timestamp"] = "";
j_tx["timestamp"] = timestamp_to_str(recieve_time); // when it got into mempool
j_tx["total_received"] = oi_identification.total_received;
j_tx["total_sent"] = 0;
j_tx["total_sent"] = 0; // to be set later when looking for key images
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["height"] = current_height; // put current blockchain height,
// just to indicate to frontend that this
// tx is younger than 10 blocks so that
// it shows unconfirmed message.
j_tx["payment_id"] = CurrentBlockchainStatus::get_payment_id_as_string(tx);
j_tx["coinbase"] = false; // mempool tx are not coinbase, so always false
j_tx["mixin"] = get_mixin_no(tx) - 1;
j_tx["mempool"] = true;
j_transactions.push_back(j_tx);
}

@ -117,7 +117,7 @@ public:
* @return json
*/
json
find_txs_in_mempool(vector<transaction> mempool_txs);
find_txs_in_mempool(vector<pair<uint64_t, transaction>> mempool_txs);
pair<account_public_address, secret_key>
get_xmr_address_viewkey() const;

@ -182,6 +182,11 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B
{
json j_tx = tx.to_json();
// mark that this is from blockchain.
// tx stored in mysql/mariadb are only from blockchain
// and never from mempool.
j_tx["mempool"] = false;
vector<XmrInput> inputs;
if (xmr_accounts->select_inputs_for_tx(tx.id, inputs))
@ -242,10 +247,11 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B
for (json& j_tx: j_mempool_tx)
{
cout << "mempool j_tx[\"total_received\"]:"
<< j_tx["total_received"]
<< endl;
//cout << "mempool j_tx[\"total_received\"]: "
// << j_tx["total_received"] << endl;
total_received_mempool += j_tx["total_received"].get<uint64_t>();
j_response["transactions"].push_back(j_tx);
}

Loading…
Cancel
Save