added tx secret key field to tx extra

This commit is contained in:
jcktm 2018-08-03 18:34:49 +10:00
parent b81214ec6e
commit 8c5a5792cb
5 changed files with 37 additions and 7 deletions

View File

@ -511,6 +511,23 @@ namespace cryptonote
add_data_to_tx_extra(tx_extra, reinterpret_cast<const char *>(&address), sizeof(address), TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR);
}
//---------------------------------------------------------------
bool get_tx_secret_key_from_tx_extra(const std::vector<uint8_t>& tx_extra, crypto::secret_key& key)
{
std::vector<tx_extra_field> tx_extra_fields;
parse_tx_extra(tx_extra, tx_extra_fields);
tx_extra_tx_secret_key seckey;
bool result = find_tx_extra_field_by_type(tx_extra_fields, seckey);
if (!result)
return false;
key = seckey.key;
return true;
}
//---------------------------------------------------------------
void add_tx_secret_key_to_tx_extra(std::vector<uint8_t>& tx_extra, const crypto::secret_key& key)
{
add_data_to_tx_extra(tx_extra, reinterpret_cast<const char *>(&key), sizeof(key), TX_EXTRA_TAG_TX_SECRET_KEY);
}
//---------------------------------------------------------------
bool get_service_node_contributor_from_tx_extra(const std::vector<uint8_t>& tx_extra, cryptonote::account_public_address& address)
{
std::vector<tx_extra_field> tx_extra_fields;

View File

@ -76,6 +76,8 @@ namespace cryptonote
bool get_service_node_pubkey_from_tx_extra(const std::vector<uint8_t>& tx_extra, crypto::public_key& pubkey);
bool get_service_node_contributor_from_tx_extra(const std::vector<uint8_t>& tx_extra, cryptonote::account_public_address& address);
bool add_service_node_register_to_tx_extra(std::vector<uint8_t>& tx_extra, const std::vector<cryptonote::account_public_address>& addresses, const std::vector<uint32_t>& portions, uint64_t expiration_timestamp, const crypto::signature& signature);
bool get_tx_secret_key_from_tx_extra(const std::vector<uint8_t>& tx_extra, crypto::secret_key& key);
void add_tx_secret_key_to_tx_extra(std::vector<uint8_t>& tx_extra, const crypto::secret_key& key);
void add_service_node_winner_to_tx_extra(std::vector<uint8_t>& tx_extra, const crypto::public_key& winner);
void add_service_node_pubkey_to_tx_extra(std::vector<uint8_t>& tx_extra, const crypto::public_key& pubkey);
void add_service_node_contributor_to_tx_extra(std::vector<uint8_t>& tx_extra, const cryptonote::account_public_address& address);

View File

@ -43,6 +43,7 @@
#define TX_EXTRA_TAG_SERVICE_NODE_WINNER 0x72
#define TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR 0x73
#define TX_EXTRA_TAG_SERVICE_NODE_PUBKEY 0x74
#define TX_EXTRA_TAG_TX_SECRET_KEY 0x75
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE
#define TX_EXTRA_NONCE_PAYMENT_ID 0x00
@ -249,6 +250,15 @@ namespace cryptonote
END_SERIALIZE()
};
struct tx_extra_tx_secret_key
{
crypto::secret_key key;
BEGIN_SERIALIZE()
FIELD(key)
END_SERIALIZE()
};
// tx_extra_field format, except tx_extra_padding and tx_extra_pub_key:
// varint tag;
// varint size;
@ -263,7 +273,8 @@ namespace cryptonote
tx_extra_service_node_register,
tx_extra_service_node_contributor,
tx_extra_service_node_winner,
tx_extra_service_node_deregister> tx_extra_field;
tx_extra_service_node_deregister,
tx_extra_tx_secret_key> tx_extra_field;
}
BLOB_SERIALIZER(cryptonote::tx_extra_service_node_deregister::vote);
@ -279,3 +290,4 @@ VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_deregister, TX_EX
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_contributor, TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_winner, TX_EXTRA_TAG_SERVICE_NODE_WINNER);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_pubkey, TX_EXTRA_TAG_SERVICE_NODE_PUBKEY);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_secret_key, TX_EXTRA_TAG_TX_SECRET_KEY);

View File

@ -782,10 +782,7 @@ namespace cryptonote
hwdev.open_tx(tx_key);
if (is_staking_tx)
{
// quietly override the tx key.
tx_key = get_deterministic_keypair_from_height(1).sec;
}
add_tx_secret_key_to_tx_extra(extra, tx_key);
// figure out if we need to make additional tx pubkeys
size_t num_stdaddresses = 0;

View File

@ -320,11 +320,14 @@ namespace service_nodes
// TODO: move unlock time check from here to below, when unlock time is done per output.
crypto::public_key pubkey;
cryptonote::account_public_address address;
crypto::secret_key gov_key;
if (!cryptonote::get_service_node_pubkey_from_tx_extra(tx.extra, pubkey))
return;
if (!cryptonote::get_service_node_contributor_from_tx_extra(tx.extra, address))
return;
if (!cryptonote::get_tx_secret_key_from_tx_extra(tx.extra, gov_key))
return;
auto iter = m_service_nodes_infos.find(pubkey);
if (iter == m_service_nodes_infos.end())
@ -333,9 +336,8 @@ namespace service_nodes
if (iter->second.is_fully_funded())
return;
cryptonote::keypair gov_key = cryptonote::get_deterministic_keypair_from_height(1);
crypto::key_derivation derivation;
if (!crypto::generate_key_derivation(address.m_view_public_key, gov_key.sec, derivation))
if (!crypto::generate_key_derivation(address.m_view_public_key, gov_key, derivation))
return;
hw::device& hwdev = hw::get_device("default");