Skip to content

Commit

Permalink
Add 'rawconfirmations' parameter for dpowconfs
Browse files Browse the repository at this point in the history
- Added some stand-in notes on the logic for rawconfirmations in wallet2
  • Loading branch information
who-biz committed Jul 13, 2019
1 parent 9e91111 commit 38d8a48
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/komodo/notary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ namespace tools

try
{
m_wallet->check_tx_key(txid, tx_key, additional_tx_keys, info.address, res.received, res.in_pool, res.confirmations);
m_wallet->check_tx_key(txid, tx_key, additional_tx_keys, info.address, res.received, res.in_pool, res.confirmations, res.rawconfirmations);
}
catch (const std::exception &e)
{
Expand Down Expand Up @@ -1657,7 +1657,8 @@ namespace tools
uint64_t received;
bool in_pool;
uint64_t confirmations;
res.good = m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, req.message, req.signature, res.received, res.in_pool, res.confirmations);
uint64_t rawconfirmations;
res.good = m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, req.message, req.signature, res.received, res.in_pool, res.confirmations, res.rawconfirmations);
}
catch (const std::exception &e)
{
Expand Down
4 changes: 4 additions & 0 deletions src/komodo/notary_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,13 @@ namespace notary_rpc
uint64_t received;
bool in_pool;
uint64_t confirmations;
uint64_t rawconfirmations;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(received)
KV_SERIALIZE(in_pool)
KV_SERIALIZE(confirmations)
KV_SERIALIZE(rawconfirmations)
END_KV_SERIALIZE_MAP()
};
};
Expand Down Expand Up @@ -1054,12 +1056,14 @@ namespace notary_rpc
uint64_t received;
bool in_pool;
uint64_t confirmations;
uint64_t rawconfirmations;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(good)
KV_SERIALIZE(received)
KV_SERIALIZE(in_pool)
KV_SERIALIZE(confirmations)
KV_SERIALIZE(rawconfirmations)
END_KV_SERIALIZE_MAP()
};
};
Expand Down
6 changes: 4 additions & 2 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5366,7 +5366,8 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
uint64_t received;
bool in_pool;
uint64_t confirmations;
m_wallet->check_tx_key(txid, tx_key, additional_tx_keys, info.address, received, in_pool, confirmations);
uint64_t rawconfirmations;
m_wallet->check_tx_key(txid, tx_key, additional_tx_keys, info.address, received, in_pool, confirmations, rawconfirmations);

if (received > 0)
{
Expand Down Expand Up @@ -5438,7 +5439,8 @@ bool simple_wallet::check_tx_proof(const std::vector<std::string> &args)
uint64_t received;
bool in_pool;
uint64_t confirmations;
if (m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, args.size() == 4 ? args[3] : "", sig_str, received, in_pool, confirmations))
uint64_t rawconfirmations;
if (m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, args.size() == 4 ? args[3] : "", sig_str, received, in_pool, confirmations, rawconfirmations))
{
success_msg_writer() << tr("Good signature");
if (received > 0)
Expand Down
37 changes: 28 additions & 9 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7791,7 +7791,7 @@ bool wallet2::check_spend_proof(const crypto::hash &txid, const std::string &mes
}
//----------------------------------------------------------------------------------------------------

void wallet2::check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations)
void wallet2::check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations, uint64_t &rawconfirmations)
{
crypto::key_derivation derivation;
THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(address.m_view_public_key, tx_key, derivation), error::wallet_internal_error,
Expand All @@ -7803,10 +7803,10 @@ void wallet2::check_tx_key(const crypto::hash &txid, const crypto::secret_key &t
THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(address.m_view_public_key, additional_tx_keys[i], additional_derivations[i]), error::wallet_internal_error,
"Failed to generate key derivation from supplied parameters");

check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations);
check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations, rawconfirmations);
}

void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations)
void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations, uint64_t &rawconfirmations)
{
COMMAND_RPC_GET_TRANSACTIONS::request req;
COMMAND_RPC_GET_TRANSACTIONS::response res;
Expand Down Expand Up @@ -7884,14 +7884,32 @@ void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_de
}

in_pool = res.txs.front().in_pool;
confirmations = (uint64_t)-1;
rawconfirmations = (uint64_t)-1;
if (!in_pool)
{
std::string err;
uint64_t bc_height = get_daemon_blockchain_height(err);
if (err.empty())
confirmations = bc_height - (res.txs.front().block_height + 1);
if (err.empty()) {
rawconfirmations = bc_height - (res.txs.front().block_height + 1);
confirmations = rawconfirmations;
}
}
#ifdef KOMODO_NOTARIZATIONS
COMMAND_RPC_GET_NTZ_DATA::response res_ntz;
if (res_ntz.notarized < (res.txs.front().block_height + 1))
{
confirmations = 0;
if (rawconfirmations > 0)
{
confirmations = 1;
// bool dpowconf_ntz = (res_ntz.notarized_hash == block_hash) TODO: not sufficient enough of a check
if (res_ntz.notarized >= (res.txs.front().block_height + 1) // && dpowconf_ntz
{
confirmations = rawconfirmations;
}
}
}
#endif
}

std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message)
Expand Down Expand Up @@ -8015,7 +8033,8 @@ std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::ac
uint64_t received;
bool in_pool;
uint64_t confirmations;
check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations);
uint64_t rawconfirmations;
check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations, rawconfirmations);
THROW_WALLET_EXCEPTION_IF(!received, error::wallet_internal_error, tr("No funds received in this tx."));

// concatenate all signature strings
Expand All @@ -8026,7 +8045,7 @@ std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::ac
return sig_str;
}

bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received, bool &in_pool, uint64_t &confirmations)
bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received, bool &in_pool, uint64_t &confirmations, uint64_t &rawconfirmations)
{
const bool is_out = sig_str.substr(0, 3) == "Out";
const std::string header = is_out ? "OutProofV1" : "InProofV1";
Expand Down Expand Up @@ -8136,7 +8155,7 @@ bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account
if (good_signature[i])
THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(shared_secret[i], rct::rct2sk(rct::I), additional_derivations[i - 1]), error::wallet_internal_error, "Failed to generate key derivation");

check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations);
check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations, rawconfirmations);
return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,10 @@ namespace tools
void segregation_height(uint64_t height) { m_segregation_height = height; }

bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
void check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations, uint64_t &rawconfirmations);
void check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations, uint64_t &rawconfirmations);
std::string get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message);
bool check_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received, bool &in_pool, uint64_t &confirmations);
bool check_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received, bool &in_pool, uint64_t &confirmations, uint64_t &rawconfirmations);

std::string get_spend_proof(const crypto::hash &txid, const std::string &message);
bool check_spend_proof(const crypto::hash &txid, const std::string &message, const std::string &sig_str);
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ namespace tools

try
{
m_wallet->check_tx_key(txid, tx_key, additional_tx_keys, info.address, res.received, res.in_pool, res.confirmations);
m_wallet->check_tx_key(txid, tx_key, additional_tx_keys, info.address, res.received, res.in_pool, res.confirmations, res.rawconfirmations);
}
catch (const std::exception &e)
{
Expand Down Expand Up @@ -1653,7 +1653,8 @@ namespace tools
uint64_t received;
bool in_pool;
uint64_t confirmations;
res.good = m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, req.message, req.signature, res.received, res.in_pool, res.confirmations);
uint64_t rawconfirmations;
res.good = m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, req.message, req.signature, res.received, res.in_pool, res.confirmations, res.rawconfirmations);
}
catch (const std::exception &e)
{
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/wallet_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,14 @@ namespace wallet_rpc
uint64_t received;
bool in_pool;
uint64_t confirmations;
uint64_t rawconfirmations;


BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(received)
KV_SERIALIZE(in_pool)
KV_SERIALIZE(confirmations)
KV_SERIALIZE(rawconfirmations)
END_KV_SERIALIZE_MAP()
};
};
Expand Down Expand Up @@ -1053,12 +1056,14 @@ namespace wallet_rpc
uint64_t received;
bool in_pool;
uint64_t confirmations;
uint64_t rawconfirmations;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(good)
KV_SERIALIZE(received)
KV_SERIALIZE(in_pool)
KV_SERIALIZE(confirmations)
KV_SERIALIZE(rawconfirmations)
END_KV_SERIALIZE_MAP()
};
};
Expand Down

0 comments on commit 38d8a48

Please sign in to comment.