aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet_rpc_server.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-06-02 13:06:41 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-06-27 21:38:21 +0100
commitdcbc17e97e782d168d1653e216d415bb4d34a892 (patch)
treea4702dae618ce6965765af1008aad4673af867e4 /src/wallet/wallet_rpc_server.cpp
parentMerge pull request #3716 (diff)
downloadmonero-dcbc17e97e782d168d1653e216d415bb4d34a892.tar.xz
wallet: include a suggested number of confirmations based on amount
This is based on how much an attacking miner stands to lose in block rewardy by mining a private chain which double spends a payment. This is not foolproof, since mining is based on luck, and breaks down as the attacking miner nears 50% of the network hash rate, and the estimation is based on a constant block reward.
Diffstat (limited to '')
-rw-r--r--src/wallet/wallet_rpc_server.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 7f7d33642..2970968e4 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -74,6 +74,21 @@ namespace
}
return pwd_container;
}
+ //------------------------------------------------------------------------------------------------------------------------------
+ void set_confirmations(tools::wallet_rpc::transfer_entry &entry, uint64_t blockchain_height, uint64_t block_reward)
+ {
+ if (entry.height >= blockchain_height)
+ {
+ entry.confirmations = 0;
+ entry.suggested_confirmations_threshold = 0;
+ return;
+ }
+ entry.confirmations = blockchain_height - entry.height;
+ if (block_reward == 0)
+ entry.suggested_confirmations_threshold = 0;
+ else
+ entry.suggested_confirmations_threshold = (entry.amount + block_reward - 1) / block_reward;
+ }
}
namespace tools
@@ -258,6 +273,7 @@ namespace tools
entry.type = "in";
entry.subaddr_index = pd.m_subaddr_index;
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
+ set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
}
//------------------------------------------------------------------------------------------------------------------------------
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd)
@@ -284,6 +300,7 @@ namespace tools
entry.type = "out";
entry.subaddr_index = { pd.m_subaddr_account, 0 };
entry.address = m_wallet->get_subaddress_as_str({pd.m_subaddr_account, 0});
+ set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
}
//------------------------------------------------------------------------------------------------------------------------------
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd)
@@ -303,6 +320,7 @@ namespace tools
entry.type = is_failed ? "failed" : "pending";
entry.subaddr_index = { pd.m_subaddr_account, 0 };
entry.address = m_wallet->get_subaddress_as_str({pd.m_subaddr_account, 0});
+ set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
}
//------------------------------------------------------------------------------------------------------------------------------
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd)
@@ -322,6 +340,7 @@ namespace tools
entry.type = "pool";
entry.subaddr_index = pd.m_subaddr_index;
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
+ set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er)