Merge branch 'master' of github.com:moneroexamples/openmonero

pull/88/head
moneroexamples 6 years ago
commit 07ae6a1dbf

@ -93,7 +93,7 @@ Download and compile recent Monero into your home folder:
# first install monero dependecines
sudo apt update
sudo apt install git build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind-dev pkg-config libssl-dev libcurl4-openssl-dev libgtest-dev libreadline-dev libzmq3-dev libsodium-dev
sudo apt install git build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind-dev pkg-config libssl-dev libcurl4-openssl-dev libgtest-dev libreadline-dev libzmq3-dev libsodium-dev libpcsclite-dev
# go to home folder
cd ~

@ -3,7 +3,7 @@ var config = {
mainnetExplorerUrl: "https://xmrchain.com/",
testnetExplorerUrl: "https://testnet.xmrchain.com/",
stagenetExplorerUrl: "http://162.210.173.150:8083/",
nettype: 2, /* 0 - MAINNET, 1 - TESTNET, 2 - STAGENET */
nettype: 1, /* 0 - MAINNET, 1 - TESTNET, 2 - STAGENET */
coinUnitPlaces: 12,
txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero
txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero

@ -244,7 +244,7 @@ CurrentBlockchainStatus::tx_exist(const string& tx_hash_str, uint64_t& tx_index)
return tx_exist(tx_hash, tx_index);
}
false;
return false;
}
bool
@ -879,8 +879,72 @@ CurrentBlockchainStatus::find_tx_in_mempool(
transaction& tx)
{
std::lock_guard<std::mutex> lck (searching_threads_map_mtx);
for (auto const& mtx: mempool_txs)
{
const transaction &m_tx = mtx.second;
if (get_transaction_hash(m_tx) == tx_hash)
{
tx = m_tx;
return true;
}
}
return false;
}
bool
CurrentBlockchainStatus::find_key_images_in_mempool(std::vector<txin_v> const& vin)
{
mempool_txs_t mempool_tx_cpy;
{
// make local copy of the mempool, so that we dont lock it for
// long, as this function can take longer to execute
std::lock_guard<std::mutex> lck (searching_threads_map_mtx);
mempool_tx_cpy = mempool_txs;
}
// perform exhostive search to check if any key image in vin vector
// is in the mempool. This is used to check if a tx generated by the frontend
// is using any key images that area already in the mempool.
for (auto const& kin: vin)
{
if(kin.type() != typeid(txin_to_key))
continue;
// get tx input key
const txin_to_key& tx_in_to_key
= boost::get<cryptonote::txin_to_key>(kin);
for (auto const& mtx: mempool_tx_cpy)
{
const transaction &m_tx = mtx.second;
vector<txin_to_key> input_key_imgs = xmreg::get_key_images(m_tx);
for (auto const& mki: input_key_imgs)
{
// if a matching key image found in the mempool
if (mki.k_image == tx_in_to_key.k_image)
return true;
}
}
}
return false;
}
bool
CurrentBlockchainStatus::find_key_images_in_mempool(transaction const& tx)
{
return find_key_images_in_mempool(tx.vin);
}
bool
CurrentBlockchainStatus::get_tx(crypto::hash const& tx_hash, transaction& tx)
{

@ -33,6 +33,12 @@ static mutex getting_mempool_txs;
*/
struct CurrentBlockchainStatus
{
// vector of mempool transactions that all threads
// can refer to
// <recieved_time, transaction>
using mempool_txs_t = vector<pair<uint64_t, transaction>>;
static string blockchain_path;
static atomic<uint64_t> current_height;
@ -65,7 +71,7 @@ struct CurrentBlockchainStatus
// vector of mempool transactions that all threads
// can refer to
// <recieved_time, transaction>
static vector<pair<uint64_t, transaction>> mempool_txs;
static mempool_txs_t mempool_txs;
// map that will keep track of search threads. In the
// map, key is address to which a running thread belongs to.
@ -192,6 +198,12 @@ struct CurrentBlockchainStatus
find_tx_in_mempool(crypto::hash const& tx_hash,
transaction& tx);
static bool
find_key_images_in_mempool(std::vector<txin_v> const& vin);
static bool
find_key_images_in_mempool(transaction const& tx);
static bool
get_tx(crypto::hash const& tx_hash, transaction& tx);

@ -251,7 +251,7 @@ OutputInputIdentification::identify_inputs(
// in all inputs in a given txs. Thus, if a single input
// is without our output, we can assume this tx does
// not contain any of our spendings.
break;
//break;
}
} // for (const txin_to_key& in_key: input_key_imgs)

@ -109,10 +109,10 @@ YourMoneroRequests::login(const shared_ptr<Session> session, const Bytes & body)
// make it 1 block lower than current, just in case.
// this variable will be our using to initialize
// `scanned_block_height` in mysql Accounts table.
if (acc_id = xmr_accounts->insert(xmr_address,
if ((acc_id = xmr_accounts->insert(xmr_address,
make_hash(view_key),
blk_timestamp_mysql_format,
current_blockchain_height) == 0)
current_blockchain_height)) == 0)
{
// if creating account failed
j_response = json {{"status", "error"},
@ -821,17 +821,56 @@ YourMoneroRequests::submit_raw_tx(const shared_ptr< Session > session, const Byt
string error_msg;
// before we submit the tx into the deamon, we are going to do a few checks.
// first, we parse the hexbuffer submmited by the frontend into binary buffer block
// second, we are going to check if we can construct valid transaction object
// fromt that binary buffer.
// third, we are going to check if any key image in this tx is in any of the txs
// in the mempool. This allows us to make a clear comment that the tx
// uses outputs just spend. This happens we a users submits few txs, one after another
// before previous txs get included in a block and are still present in the mempool.
std::string tx_blob;
if(!epee::string_tools::parse_hexstr_to_binbuff(raw_tx_blob, tx_blob))
{
j_response["status"] = "error";
j_response["error"] = "Tx faild parse_hexstr_to_binbuff";
session_close(session, j_response.dump());
return;
}
transaction tx_to_be_submitted;
if (!parse_and_validate_tx_from_blob(tx_blob, tx_to_be_submitted))
{
j_response["status"] = "error";
j_response["error"] = "Tx faild parse_and_validate_tx_from_blob";
session_close(session, j_response.dump());
return;
}
if (CurrentBlockchainStatus::find_key_images_in_mempool(tx_to_be_submitted))
{
j_response["status"] = "error";
j_response["error"] = "Tx uses your outputs that area already in the mempool. "
"Please wait till your previous tx(s) get mined";
session_close(session, j_response.dump());
return;
}
if (!CurrentBlockchainStatus::commit_tx(
raw_tx_blob, error_msg,
CurrentBlockchainStatus::do_not_relay))
{
j_response["status"] = "error";
j_response["error"] = error_msg;
session_close(session, j_response.dump());
return;
}
else
{
j_response["status"] = "success";
}
j_response["status"] = "success";
string response_body = j_response.dump();

Loading…
Cancel
Save