mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
Merge pull request #2205
c97d1bd3
wallet: return unlock_time in get_transfers (moneromooo-monero)
This commit is contained in:
commit
68ccc10b29
@ -3867,6 +3867,22 @@ static std::string get_human_readable_timestamp(uint64_t ts)
|
||||
return std::string(buffer);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
static std::string get_human_readable_timespan(std::chrono::seconds seconds)
|
||||
{
|
||||
uint64_t ts = seconds.count();
|
||||
if (ts < 60)
|
||||
return std::to_string(ts) + tr(" seconds");
|
||||
if (ts < 3600)
|
||||
return std::to_string((uint64_t)(ts / 60)) + tr(" minutes");
|
||||
if (ts < 3600 * 24)
|
||||
return std::to_string((uint64_t)(ts / 3600)) + tr(" hours");
|
||||
if (ts < 3600 * 24 * 30.5)
|
||||
return std::to_string((uint64_t)(ts / (3600 * 24))) + tr(" days");
|
||||
if (ts < 3600 * 24 * 365.25)
|
||||
return std::to_string((uint64_t)(ts / (3600 * 24 * 365.25))) + tr(" months");
|
||||
return tr("a long time");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
||||
{
|
||||
std::vector<std::string> local_args = args_;
|
||||
@ -4673,6 +4689,8 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
|
||||
}
|
||||
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
|
||||
|
||||
const uint64_t last_block_height = m_wallet->get_blockchain_current_height();
|
||||
|
||||
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
|
||||
m_wallet->get_payments(payments, 0);
|
||||
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
|
||||
@ -4687,6 +4705,23 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
|
||||
success_msg_writer() << "Timestamp: " << get_human_readable_timestamp(pd.m_timestamp);
|
||||
success_msg_writer() << "Amount: " << print_money(pd.m_amount);
|
||||
success_msg_writer() << "Payment ID: " << payment_id;
|
||||
if (pd.m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER)
|
||||
{
|
||||
uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE);
|
||||
if (bh >= last_block_height)
|
||||
success_msg_writer() << "Locked: " << (bh - last_block_height) << " blocks to unlock";
|
||||
else
|
||||
success_msg_writer() << std::to_string(last_block_height - bh) << " confirmations";
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t current_time = static_cast<uint64_t>(time(NULL));
|
||||
uint64_t threshold = current_time + (m_wallet->use_fork_rules(2, 0) ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1);
|
||||
if (threshold >= pd.m_unlock_time)
|
||||
success_msg_writer() << "unlocked for " << get_human_readable_timespan(std::chrono::seconds(threshold - pd.m_unlock_time));
|
||||
else
|
||||
success_msg_writer() << "locked for " << get_human_readable_timespan(std::chrono::seconds(pd.m_unlock_time - threshold));
|
||||
}
|
||||
success_msg_writer() << "Note: " << m_wallet->get_tx_note(txid);
|
||||
return true;
|
||||
}
|
||||
|
@ -1097,6 +1097,7 @@ void wallet2::process_outgoing(const crypto::hash &txid, const cryptonote::trans
|
||||
}
|
||||
entry.first->second.m_block_height = height;
|
||||
entry.first->second.m_timestamp = ts;
|
||||
entry.first->second.m_unlock_time = tx.unlock_time;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const crypto::hash& bl_id, uint64_t height, const cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices &o_indices)
|
||||
|
@ -199,10 +199,11 @@ namespace tools
|
||||
std::vector<cryptonote::tx_destination_entry> m_dests;
|
||||
crypto::hash m_payment_id;
|
||||
uint64_t m_timestamp;
|
||||
uint64_t m_unlock_time;
|
||||
|
||||
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(cryptonote::null_hash) {}
|
||||
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(cryptonote::null_hash), m_timestamp(0), m_unlock_time(0) {}
|
||||
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height):
|
||||
m_amount_in(utd.m_amount_in), m_amount_out(utd.m_amount_out), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id), m_timestamp(utd.m_timestamp) {}
|
||||
m_amount_in(utd.m_amount_in), m_amount_out(utd.m_amount_out), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id), m_timestamp(utd.m_timestamp), m_unlock_time(utd.m_tx.unlock_time) {}
|
||||
};
|
||||
|
||||
struct tx_construction_data
|
||||
@ -704,7 +705,7 @@ BOOST_CLASS_VERSION(tools::wallet2, 18)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 7)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::payment_details, 1)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 6)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 3)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 4)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 16)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0)
|
||||
BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 0)
|
||||
@ -879,6 +880,13 @@ namespace boost
|
||||
x.m_amount_out += x.m_change;
|
||||
}
|
||||
}
|
||||
if (ver < 4)
|
||||
{
|
||||
if (!typename Archive::is_saving())
|
||||
x.m_unlock_time = 0;
|
||||
return;
|
||||
}
|
||||
a & x.m_unlock_time;
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
|
@ -236,6 +236,7 @@ namespace tools
|
||||
entry.height = pd.m_block_height;
|
||||
entry.timestamp = pd.m_timestamp;
|
||||
entry.amount = pd.m_amount;
|
||||
entry.unlock_time = pd.m_unlock_time;
|
||||
entry.fee = 0; // TODO
|
||||
entry.note = m_wallet->get_tx_note(pd.m_tx_hash);
|
||||
entry.type = "in";
|
||||
@ -249,6 +250,7 @@ namespace tools
|
||||
entry.payment_id = entry.payment_id.substr(0,16);
|
||||
entry.height = pd.m_block_height;
|
||||
entry.timestamp = pd.m_timestamp;
|
||||
entry.unlock_time = pd.m_unlock_time;
|
||||
entry.fee = pd.m_amount_in - pd.m_amount_out;
|
||||
uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known
|
||||
entry.amount = pd.m_amount_in - change - entry.fee;
|
||||
@ -276,6 +278,7 @@ namespace tools
|
||||
entry.timestamp = pd.m_timestamp;
|
||||
entry.fee = pd.m_amount_in - pd.m_amount_out;
|
||||
entry.amount = pd.m_amount_in - pd.m_change - entry.fee;
|
||||
entry.unlock_time = pd.m_tx.unlock_time;
|
||||
entry.note = m_wallet->get_tx_note(txid);
|
||||
entry.type = is_failed ? "failed" : "pending";
|
||||
}
|
||||
@ -289,6 +292,7 @@ namespace tools
|
||||
entry.height = 0;
|
||||
entry.timestamp = pd.m_timestamp;
|
||||
entry.amount = pd.m_amount;
|
||||
entry.unlock_time = pd.m_unlock_time;
|
||||
entry.fee = 0; // TODO
|
||||
entry.note = m_wallet->get_tx_note(pd.m_tx_hash);
|
||||
entry.type = "pool";
|
||||
|
@ -560,6 +560,7 @@ namespace wallet_rpc
|
||||
std::string note;
|
||||
std::list<transfer_destination> destinations;
|
||||
std::string type;
|
||||
uint64_t unlock_time;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(txid);
|
||||
@ -571,6 +572,7 @@ namespace wallet_rpc
|
||||
KV_SERIALIZE(note);
|
||||
KV_SERIALIZE(destinations);
|
||||
KV_SERIALIZE(type);
|
||||
KV_SERIALIZE(unlock_time)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user