rpc: is_key_image_spent now checks the tx pool too

This commit is contained in:
moneromooo-monero 2016-01-05 21:57:43 +00:00
parent 10cc6a8593
commit a44d94d390
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
3 changed files with 40 additions and 4 deletions

View File

@ -304,7 +304,37 @@ namespace cryptonote
} }
res.spent_status.clear(); res.spent_status.clear();
for (size_t n = 0; n < spent_status.size(); ++n) for (size_t n = 0; n < spent_status.size(); ++n)
res.spent_status.push_back(spent_status[n]); res.spent_status.push_back(spent_status[n] ? COMMAND_RPC_IS_KEY_IMAGE_SPENT::SPENT_IN_BLOCKCHAIN : COMMAND_RPC_IS_KEY_IMAGE_SPENT::UNSPENT);
// check the pool too
std::vector<cryptonote::tx_info> txs;
std::vector<cryptonote::spent_key_image_info> ki;
r = m_core.get_pool_transactions_and_spent_keys_info(txs, ki);
if(!r)
{
res.status = "Failed";
return true;
}
for (std::vector<cryptonote::spent_key_image_info>::const_iterator i = ki.begin(); i != ki.end(); ++i)
{
crypto::hash hash;
crypto::key_image spent_key_image;
if (parse_hash256(i->id_hash, hash))
{
memcpy(&spent_key_image, &hash, sizeof(hash)); // a bit dodgy, should be other parse functions somewhere
for (size_t n = 0; n < res.spent_status.size(); ++n)
{
if (res.spent_status[n] == COMMAND_RPC_IS_KEY_IMAGE_SPENT::UNSPENT)
{
if (key_images[n] == spent_key_image)
{
res.spent_status[n] = COMMAND_RPC_IS_KEY_IMAGE_SPENT::SPENT_IN_POOL;
break;
}
}
}
}
}
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; return true;

View File

@ -123,6 +123,12 @@ namespace cryptonote
//----------------------------------------------- //-----------------------------------------------
struct COMMAND_RPC_IS_KEY_IMAGE_SPENT struct COMMAND_RPC_IS_KEY_IMAGE_SPENT
{ {
enum STATUS {
UNSPENT = 0,
SPENT_IN_BLOCKCHAIN = 1,
SPENT_IN_POOL = 2,
};
struct request struct request
{ {
std::vector<std::string> key_images; std::vector<std::string> key_images;

View File

@ -1419,15 +1419,15 @@ void wallet2::rescan_spent()
for (size_t i = 0; i < m_transfers.size(); ++i) for (size_t i = 0; i < m_transfers.size(); ++i)
{ {
transfer_details& td = m_transfers[i]; transfer_details& td = m_transfers[i];
if (td.m_spent != daemon_resp.spent_status[i]) if (td.m_spent != (daemon_resp.spent_status[i] != COMMAND_RPC_IS_KEY_IMAGE_SPENT::UNSPENT))
{ {
if (td.m_spent) if (td.m_spent)
{ {
LOG_PRINT_L1("Marking output " << i << " as unspent, it was marked as spent"); LOG_PRINT_L0("Marking output " << i << "(" << td.m_key_image << ") as unspent, it was marked as spent");
} }
else else
{ {
LOG_PRINT_L1("Marking output " << i << " as spent, it was marked as unspent"); LOG_PRINT_L0("Marking output " << i << "(" << td.m_key_image << ") as spent, it was marked as unspent");
} }
td.m_spent = daemon_resp.spent_status[i]; td.m_spent = daemon_resp.spent_status[i];
} }