Add a constructor for tx_extra_loki_name_system and use it

This commit is contained in:
Doyle 2020-02-10 10:04:19 +11:00
parent 528e41bec1
commit f460fc08ba
3 changed files with 17 additions and 16 deletions

View File

@ -403,6 +403,16 @@ namespace cryptonote
std::string value; // binary format of the name->value mapping
crypto::hash prev_txid = crypto::null_hash; // previous txid that purchased the mapping, only applicable if lokinet
tx_extra_loki_name_system() = default;
tx_extra_loki_name_system(crypto::ed25519_public_key const &owner, uint16_t type, std::string const &name, std::string const &value, crypto::hash const &prev_txid)
: owner(owner)
, type(type)
, name(name)
, value(value)
, prev_txid(prev_txid)
{
}
BEGIN_SERIALIZE()
FIELD(version);
FIELD(owner);

View File

@ -8582,11 +8582,7 @@ std::vector<wallet2::pending_tx> wallet2::create_buy_lns_mapping_tx(uint16_t typ
crypto_sign_ed25519_seed_keypair(pkey.data, skey.data, reinterpret_cast<const unsigned char *>(&m_account.get_keys().m_spend_secret_key));
}
tx_extra_loki_name_system entry = {};
entry.owner = pkey;
entry.type = type;
entry.name = name;
entry.value.resize(value_blob.len);
crypto::hash prev_txid = crypto::null_hash;
if (type == static_cast<uint16_t>(lns::mapping_type::lokinet))
{
std::vector<cryptonote::COMMAND_RPC_GET_LNS_NAMES_TO_OWNERS::request_entry> request = {};
@ -8605,10 +8601,10 @@ std::vector<wallet2::pending_tx> wallet2::create_buy_lns_mapping_tx(uint16_t typ
return {};
}
entry.prev_txid = response.empty() ? crypto::null_hash : response[0].txid;
if (response.size()) prev_txid = response[0].txid;
}
memcpy(&entry.value[0], value_blob.buffer.data(), value_blob.len);
tx_extra_loki_name_system entry(pkey, type, name, value, prev_txid);
std::vector<uint8_t> extra;
add_loki_name_system_to_tx_extra(extra, entry);

View File

@ -523,20 +523,15 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx(crypton
uint8_t new_hf_version = get_hf_version_at(new_height);
if (burn == LNS_AUTO_BURN) burn = lns::burn_requirement_in_atomic_loki(new_hf_version);
std::vector<uint8_t> extra;
cryptonote::tx_extra_loki_name_system data = {};
data.owner = pkey;
data.type = type;
data.value = value;
data.name = name;
crypto::hash prev_txid = crypto::null_hash;
if (type == static_cast<uint16_t>(lns::mapping_type::lokinet))
{
if (lns::mapping_record mapping = lns_db_.get_mapping(type, name))
data.prev_txid = mapping.txid;
else
data.prev_txid = crypto::null_hash;
prev_txid = mapping.txid;
}
std::vector<uint8_t> extra;
cryptonote::tx_extra_loki_name_system data(pkey, type, name, value, prev_txid);
cryptonote::add_loki_name_system_to_tx_extra(extra, data);
cryptonote::add_burned_amount_to_tx_extra(extra, burn);
cryptonote::transaction result = {};