mirror of
https://git.wownero.com/wownero/wownero.git
synced 2025-02-02 15:38:36 +00:00
commit
6e43f020ae
@ -172,11 +172,16 @@ namespace epee
|
|||||||
|
|
||||||
byte_slice::byte_slice(byte_stream&& stream) noexcept
|
byte_slice::byte_slice(byte_stream&& stream) noexcept
|
||||||
: storage_(nullptr), portion_(stream.data(), stream.size())
|
: storage_(nullptr), portion_(stream.data(), stream.size())
|
||||||
|
{
|
||||||
|
if (stream.size())
|
||||||
{
|
{
|
||||||
std::uint8_t* const data = stream.take_buffer().release() - sizeof(raw_byte_slice);
|
std::uint8_t* const data = stream.take_buffer().release() - sizeof(raw_byte_slice);
|
||||||
new (data) raw_byte_slice{};
|
new (data) raw_byte_slice{};
|
||||||
storage_.reset(reinterpret_cast<raw_byte_slice*>(data));
|
storage_.reset(reinterpret_cast<raw_byte_slice*>(data));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
portion_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
byte_slice::byte_slice(byte_slice&& source) noexcept
|
byte_slice::byte_slice(byte_slice&& source) noexcept
|
||||||
: storage_(std::move(source.storage_)), portion_(source.portion_)
|
: storage_(std::move(source.storage_)), portion_(source.portion_)
|
||||||
@ -205,6 +210,9 @@ namespace epee
|
|||||||
byte_slice byte_slice::take_slice(const std::size_t max_bytes) noexcept
|
byte_slice byte_slice::take_slice(const std::size_t max_bytes) noexcept
|
||||||
{
|
{
|
||||||
byte_slice out{};
|
byte_slice out{};
|
||||||
|
|
||||||
|
if (max_bytes)
|
||||||
|
{
|
||||||
std::uint8_t const* const ptr = data();
|
std::uint8_t const* const ptr = data();
|
||||||
out.portion_ = {ptr, portion_.remove_prefix(max_bytes)};
|
out.portion_ = {ptr, portion_.remove_prefix(max_bytes)};
|
||||||
|
|
||||||
@ -212,7 +220,7 @@ namespace epee
|
|||||||
out.storage_ = std::move(storage_); // no atomic inc/dec
|
out.storage_ = std::move(storage_); // no atomic inc/dec
|
||||||
else
|
else
|
||||||
out = {storage_.get(), out.portion_};
|
out = {storage_.get(), out.portion_};
|
||||||
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -916,6 +916,7 @@ difficulty_type Blockchain::get_difficulty_for_next_block()
|
|||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
std::vector<time_t> Blockchain::get_last_block_timestamps(unsigned int blocks) const
|
std::vector<time_t> Blockchain::get_last_block_timestamps(unsigned int blocks) const
|
||||||
{
|
{
|
||||||
|
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||||
uint64_t height = m_db->height();
|
uint64_t height = m_db->height();
|
||||||
if (blocks > height)
|
if (blocks > height)
|
||||||
blocks = height;
|
blocks = height;
|
||||||
|
@ -5466,7 +5466,7 @@ void simple_wallet::on_new_block(uint64_t height, const cryptonote::block& block
|
|||||||
m_refresh_progress_reporter.update(height, false);
|
m_refresh_progress_reporter.update(height, false);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
void simple_wallet::on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time)
|
void simple_wallet::on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time)
|
||||||
{
|
{
|
||||||
if (m_locked)
|
if (m_locked)
|
||||||
return;
|
return;
|
||||||
@ -5477,7 +5477,7 @@ void simple_wallet::on_money_received(uint64_t height, const crypto::hash &txid,
|
|||||||
tr("idx ") << subaddr_index;
|
tr("idx ") << subaddr_index;
|
||||||
|
|
||||||
const uint64_t warn_height = m_wallet->nettype() == TESTNET ? 1000000 : m_wallet->nettype() == STAGENET ? 50000 : 1650000;
|
const uint64_t warn_height = m_wallet->nettype() == TESTNET ? 1000000 : m_wallet->nettype() == STAGENET ? 50000 : 1650000;
|
||||||
if (height >= warn_height)
|
if (height >= warn_height && !is_change)
|
||||||
{
|
{
|
||||||
std::vector<tx_extra_field> tx_extra_fields;
|
std::vector<tx_extra_field> tx_extra_fields;
|
||||||
parse_tx_extra(tx.extra, tx_extra_fields); // failure ok
|
parse_tx_extra(tx.extra, tx_extra_fields); // failure ok
|
||||||
|
@ -342,7 +342,7 @@ namespace cryptonote
|
|||||||
|
|
||||||
//----------------- i_wallet2_callback ---------------------
|
//----------------- i_wallet2_callback ---------------------
|
||||||
virtual void on_new_block(uint64_t height, const cryptonote::block& block);
|
virtual void on_new_block(uint64_t height, const cryptonote::block& block);
|
||||||
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time);
|
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time);
|
||||||
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index);
|
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index);
|
||||||
virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index);
|
virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index);
|
||||||
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx);
|
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx);
|
||||||
|
@ -157,7 +157,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time)
|
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
|
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
|
||||||
|
@ -1869,6 +1869,20 @@ void wallet2::cache_tx_data(const cryptonote::transaction& tx, const crypto::has
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool wallet2::spends_one_of_ours(const cryptonote::transaction &tx) const
|
||||||
|
{
|
||||||
|
for (const auto &in: tx.vin)
|
||||||
|
{
|
||||||
|
if (in.type() != typeid(cryptonote::txin_to_key))
|
||||||
|
continue;
|
||||||
|
const cryptonote::txin_to_key &in_to_key = boost::get<cryptonote::txin_to_key>(in);
|
||||||
|
auto it = m_key_images.find(in_to_key.k_image);
|
||||||
|
if (it != m_key_images.end())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &o_indices, uint64_t height, uint8_t block_version, uint64_t ts, bool miner_tx, bool pool, bool double_spend_seen, const tx_cache_data &tx_cache_data, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache)
|
void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &o_indices, uint64_t height, uint8_t block_version, uint64_t ts, bool miner_tx, bool pool, bool double_spend_seen, const tx_cache_data &tx_cache_data, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache)
|
||||||
{
|
{
|
||||||
PERF_TIMER(process_new_transaction);
|
PERF_TIMER(process_new_transaction);
|
||||||
@ -2155,7 +2169,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
|||||||
}
|
}
|
||||||
LOG_PRINT_L0("Received money: " << print_money(td.amount()) << ", with tx: " << txid);
|
LOG_PRINT_L0("Received money: " << print_money(td.amount()) << ", with tx: " << txid);
|
||||||
if (0 != m_callback)
|
if (0 != m_callback)
|
||||||
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index, td.m_tx.unlock_time);
|
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index, spends_one_of_ours(tx), td.m_tx.unlock_time);
|
||||||
}
|
}
|
||||||
total_received_1 += amount;
|
total_received_1 += amount;
|
||||||
notify = true;
|
notify = true;
|
||||||
@ -2232,7 +2246,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
|||||||
|
|
||||||
LOG_PRINT_L0("Received money: " << print_money(td.amount()) << ", with tx: " << txid);
|
LOG_PRINT_L0("Received money: " << print_money(td.amount()) << ", with tx: " << txid);
|
||||||
if (0 != m_callback)
|
if (0 != m_callback)
|
||||||
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index, td.m_tx.unlock_time);
|
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index, spends_one_of_ours(tx), td.m_tx.unlock_time);
|
||||||
}
|
}
|
||||||
total_received_1 += extra_amount;
|
total_received_1 += extra_amount;
|
||||||
notify = true;
|
notify = true;
|
||||||
|
@ -131,7 +131,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
// Full wallet callbacks
|
// Full wallet callbacks
|
||||||
virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
|
virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
|
||||||
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time) {}
|
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time) {}
|
||||||
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {}
|
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {}
|
||||||
virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {}
|
virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {}
|
||||||
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
|
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
|
||||||
@ -1517,6 +1517,7 @@ private:
|
|||||||
void check_rpc_cost(const char *call, uint64_t post_call_credits, uint64_t pre_credits, double expected_cost);
|
void check_rpc_cost(const char *call, uint64_t post_call_credits, uint64_t pre_credits, double expected_cost);
|
||||||
|
|
||||||
bool should_expand(const cryptonote::subaddress_index &index) const;
|
bool should_expand(const cryptonote::subaddress_index &index) const;
|
||||||
|
bool spends_one_of_ours(const cryptonote::transaction &tx) const;
|
||||||
|
|
||||||
cryptonote::account_base m_account;
|
cryptonote::account_base m_account;
|
||||||
boost::optional<epee::net_utils::http::login> m_daemon_login;
|
boost::optional<epee::net_utils::http::login> m_daemon_login;
|
||||||
|
@ -667,6 +667,23 @@ TEST(ByteSlice, TakeSlice)
|
|||||||
EXPECT_TRUE(boost::range::equal(base_string, slice));
|
EXPECT_TRUE(boost::range::equal(base_string, slice));
|
||||||
|
|
||||||
const epee::span<const std::uint8_t> original = epee::to_span(slice);
|
const epee::span<const std::uint8_t> original = epee::to_span(slice);
|
||||||
|
const epee::byte_slice empty_slice = slice.take_slice(0);
|
||||||
|
EXPECT_EQ(original.begin(), slice.begin());
|
||||||
|
EXPECT_EQ(slice.begin(), slice.cbegin());
|
||||||
|
EXPECT_EQ(original.end(), slice.end());
|
||||||
|
EXPECT_EQ(slice.end(), slice.cend());
|
||||||
|
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.begin());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.cbegin());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.end());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.cend());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.data());
|
||||||
|
EXPECT_TRUE(empty_slice.empty());
|
||||||
|
EXPECT_EQ(0u, empty_slice.size());
|
||||||
|
|
||||||
|
EXPECT_FALSE(slice.empty());
|
||||||
|
EXPECT_EQ(slice.cbegin(), slice.data());
|
||||||
|
|
||||||
const epee::byte_slice slice2 = slice.take_slice(remove_size);
|
const epee::byte_slice slice2 = slice.take_slice(remove_size);
|
||||||
|
|
||||||
EXPECT_EQ(original.begin() + remove_size, slice.begin());
|
EXPECT_EQ(original.begin() + remove_size, slice.begin());
|
||||||
@ -1061,6 +1078,20 @@ TEST(ByteStream, ToByteSlice)
|
|||||||
EXPECT_EQ(nullptr, stream.data());
|
EXPECT_EQ(nullptr, stream.data());
|
||||||
EXPECT_EQ(nullptr, stream.tellp());
|
EXPECT_EQ(nullptr, stream.tellp());
|
||||||
EXPECT_TRUE(equal(source, slice));
|
EXPECT_TRUE(equal(source, slice));
|
||||||
|
|
||||||
|
stream = epee::byte_stream{};
|
||||||
|
stream.reserve(1);
|
||||||
|
EXPECT_NE(nullptr, stream.data());
|
||||||
|
EXPECT_NE(nullptr, stream.tellp());
|
||||||
|
|
||||||
|
const epee::byte_slice empty_slice{std::move(stream)};
|
||||||
|
EXPECT_TRUE(empty_slice.empty());
|
||||||
|
EXPECT_EQ(0u, empty_slice.size());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.begin());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.cbegin());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.end());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.cend());
|
||||||
|
EXPECT_EQ(nullptr, empty_slice.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ToHex, String)
|
TEST(ToHex, String)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user