mirror of https://github.com/oxen-io/oxen-core.git
Mask the name by hashing using sodium's blake2b
This commit is contained in:
parent
77cda2ad48
commit
5f0c146e07
|
@ -400,28 +400,28 @@ namespace cryptonote
|
|||
lns::mapping_type type; // alias to lns::mapping_type
|
||||
crypto::ed25519_public_key owner; // only serialized if command == tx_command_t::buy
|
||||
crypto::ed25519_signature signature; // only serialized if command == tx_command_t::update
|
||||
std::string name;
|
||||
crypto::hash name_hash;
|
||||
std::string value; // binary format of the name->value mapping
|
||||
crypto::hash prev_txid = crypto::null_hash; // previous txid that purchased the mapping
|
||||
|
||||
static tx_extra_loki_name_system make_buy(crypto::ed25519_public_key const &owner, lns::mapping_type type, std::string const &name, std::string const &value, crypto::hash const &prev_txid)
|
||||
static tx_extra_loki_name_system make_buy(crypto::ed25519_public_key const &owner, lns::mapping_type type, crypto::hash const &name_hash, std::string const &value, crypto::hash const &prev_txid)
|
||||
{
|
||||
tx_extra_loki_name_system result = {};
|
||||
result.owner = owner;
|
||||
result.type = type;
|
||||
result.name = name;
|
||||
result.name_hash = name_hash;
|
||||
result.value = value;
|
||||
result.prev_txid = prev_txid;
|
||||
result.command = lns::tx_command_t::buy;
|
||||
return result;
|
||||
}
|
||||
|
||||
static tx_extra_loki_name_system make_update(crypto::ed25519_signature const &signature, lns::mapping_type type, std::string const &name, std::string const &value, crypto::hash const &prev_txid)
|
||||
static tx_extra_loki_name_system make_update(crypto::ed25519_signature const &signature, lns::mapping_type type, crypto::hash const &name_hash, std::string const &value, crypto::hash const &prev_txid)
|
||||
{
|
||||
tx_extra_loki_name_system result = {};
|
||||
result.signature = signature;
|
||||
result.type = type;
|
||||
result.name = name;
|
||||
result.name_hash = name_hash;
|
||||
result.value = value;
|
||||
result.prev_txid = prev_txid;
|
||||
result.command = lns::tx_command_t::update;
|
||||
|
@ -436,7 +436,7 @@ namespace cryptonote
|
|||
FIELD(owner)
|
||||
else
|
||||
FIELD(signature)
|
||||
FIELD(name)
|
||||
FIELD(name_hash)
|
||||
FIELD(value)
|
||||
FIELD(prev_txid)
|
||||
END_SERIALIZE()
|
||||
|
|
|
@ -62,7 +62,7 @@ enum struct mapping_record_row
|
|||
{
|
||||
id,
|
||||
type,
|
||||
name,
|
||||
name_hash,
|
||||
value,
|
||||
txid,
|
||||
prev_txid,
|
||||
|
@ -142,15 +142,13 @@ static bool sql_run_statement(cryptonote::network_type nettype, lns_sql_type typ
|
|||
tmp_entry.register_height = static_cast<uint16_t>(sqlite3_column_int(statement, static_cast<int>(mapping_record_row::register_height)));
|
||||
tmp_entry.owner_id = sqlite3_column_int(statement, static_cast<int>(mapping_record_row::owner_id));
|
||||
|
||||
int name_len = sqlite3_column_bytes(statement, static_cast<int>(mapping_record_row::name));
|
||||
auto *name = reinterpret_cast<char const *>(sqlite3_column_text(statement, static_cast<int>(mapping_record_row::name)));
|
||||
|
||||
size_t value_len = static_cast<size_t>(sqlite3_column_bytes(statement, static_cast<int>(mapping_record_row::value)));
|
||||
auto *value = reinterpret_cast<char const *>(sqlite3_column_text(statement, static_cast<int>(mapping_record_row::value)));
|
||||
|
||||
tmp_entry.name = std::string(name, name_len);
|
||||
tmp_entry.value = std::string(value, value_len);
|
||||
|
||||
if (!sql_copy_blob(statement, static_cast<int>(mapping_record_row::name_hash), tmp_entry.name_hash.data, sizeof(tmp_entry.name_hash)))
|
||||
return false;
|
||||
|
||||
if (!sql_copy_blob(statement, static_cast<int>(mapping_record_row::txid), tmp_entry.txid.data, sizeof(tmp_entry.txid)))
|
||||
return false;
|
||||
|
||||
|
@ -419,7 +417,7 @@ static bool check_lengths(mapping_type type, std::string const &value, size_t ma
|
|||
if (reason)
|
||||
{
|
||||
std::stringstream err_stream;
|
||||
err_stream << "LNS type=" << type << ", specifies mapping from name -> value where the value's length=" << value.size();
|
||||
err_stream << "LNS type=" << type << ", specifies mapping from name_hash->value where the value's length=" << value.size();
|
||||
if (require_exact_len) err_stream << ", does not equal the required length=";
|
||||
else err_stream <<" is 0 or exceeds the maximum length=";
|
||||
err_stream << max << ", given value=" << value;
|
||||
|
@ -543,7 +541,7 @@ bool validate_lns_value(cryptonote::network_type nettype, mapping_type type, std
|
|||
{
|
||||
if (reason)
|
||||
{
|
||||
err_stream << "LNS type=session, specifies mapping from name -> ed25519 key where the key is not prefixed with 53 (0x05), prefix=" << std::to_string(value[0]) << " (" << value[0] << "), given ed25519=" << value;
|
||||
err_stream << "LNS type=session, specifies mapping from name_hash->ed25519 key where the key is not prefixed with 53 (0x05), prefix=" << std::to_string(value[0]) << " (" << value[0] << "), given ed25519=" << value;
|
||||
*reason = err_stream.str();
|
||||
}
|
||||
return false;
|
||||
|
@ -575,7 +573,7 @@ bool validate_lns_value_binary(mapping_type type, std::string const &value, std:
|
|||
if (reason)
|
||||
{
|
||||
std::stringstream err_stream;
|
||||
err_stream << "LNS type=" << type << ", specifies mapping from name -> wallet address where the wallet address's blob, does not generate valid public spend/view keys";
|
||||
err_stream << "LNS type=" << type << ", specifies mapping from name_hash->wallet address where the wallet address's blob, does not generate valid public spend/view keys";
|
||||
*reason = err_stream.str();
|
||||
}
|
||||
return false;
|
||||
|
@ -592,7 +590,7 @@ static std::ostream &operator<<(std::ostream &stream, cryptonote::tx_extra_loki_
|
|||
else
|
||||
stream << "signature=" << epee::string_tools::pod_to_hex(data.signature);
|
||||
|
||||
stream << ", type=" << data.type << ", name=" << data.name << "}";
|
||||
stream << ", type=" << data.type << ", name_hash=" << data.name_hash << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
@ -600,8 +598,7 @@ static bool validate_against_previous_mapping(lns::name_system_db const &lns_db,
|
|||
{
|
||||
std::stringstream err_stream;
|
||||
crypto::hash expected_prev_txid = crypto::null_hash;
|
||||
lns::mapping_record mapping = lns_db.get_mapping(data.type, data.name);
|
||||
|
||||
lns::mapping_record mapping = lns_db.get_mapping(data.type, data.name_hash);
|
||||
const bool updating = data.command == lns::tx_command_t::update;
|
||||
if (updating && !mapping)
|
||||
{
|
||||
|
@ -661,7 +658,7 @@ static bool validate_against_previous_mapping(lns::name_system_db const &lns_db,
|
|||
if (reason)
|
||||
{
|
||||
lns::owner_record owner = lns_db.get_owner_by_id(mapping.owner_id);
|
||||
err_stream << tx << ", " << data << ", non-lokinet entries can NOT be renewed, mapping already exists with name=" << mapping.name << ", owner=" << owner.key << ", type=" << mapping.type;
|
||||
err_stream << tx << ", " << data << ", non-lokinet entries can NOT be renewed, mapping already exists with name_hash=" << mapping.name_hash << ", owner=" << owner.key << ", type=" << mapping.type;
|
||||
*reason = err_stream.str();
|
||||
}
|
||||
return false;
|
||||
|
@ -777,18 +774,27 @@ bool name_system_db::validate_lns_tx(uint8_t hf_version, uint64_t blockchain_hei
|
|||
}
|
||||
return false;
|
||||
}
|
||||
if (!validate_lns_name(entry->type, entry->name, reason))
|
||||
return false;
|
||||
|
||||
if (!validate_lns_value_binary(entry->type, entry->value, reason))
|
||||
return false;
|
||||
return false;
|
||||
|
||||
if (!validate_against_previous_mapping(*this, blockchain_height, tx, *entry, reason))
|
||||
return false;
|
||||
|
||||
static const crypto::hash null_name_hash = name_to_hash(""); // Sanity check the empty name hash
|
||||
if (entry->name_hash == null_name_hash || entry->name_hash == crypto::null_hash)
|
||||
{
|
||||
if (reason)
|
||||
{
|
||||
err_stream << "LNS TX=" << cryptonote::get_transaction_hash(tx) << ", specified the null name hash";
|
||||
*reason = err_stream.str();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool updating = entry->command == lns::tx_command_t::update;
|
||||
uint64_t burn = cryptonote::get_burned_amount_from_tx_extra(tx.extra);
|
||||
uint64_t burn_required = updating ? 0 : burn_needed(hf_version, static_cast<lns::mapping_type>(entry->type));
|
||||
uint64_t burn_required = updating ? 0 : burn_needed(hf_version, entry->type);
|
||||
if (burn != burn_required)
|
||||
{
|
||||
if (reason)
|
||||
|
@ -830,6 +836,19 @@ bool validate_mapping_type(std::string const &mapping_type_str, lns::mapping_typ
|
|||
return true;
|
||||
}
|
||||
|
||||
crypto::hash name_to_hash(std::string const &name)
|
||||
{
|
||||
crypto::hash result = {};
|
||||
static_assert(sizeof(result) >= crypto_generichash_BYTES, "Sodium can generate arbitrary length hashes, but recommend the minimum size for a secure hash must be >= crypto_generichash_BYTES");
|
||||
crypto_generichash_blake2b(reinterpret_cast<unsigned char *>(result.data),
|
||||
sizeof(result),
|
||||
reinterpret_cast<const unsigned char *>(name.data()),
|
||||
static_cast<unsigned long long>(name.size()),
|
||||
nullptr /*key*/,
|
||||
0 /*keylen*/);
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool build_default_tables(sqlite3 *db)
|
||||
{
|
||||
constexpr char BUILD_TABLE_SQL[] = R"(
|
||||
|
@ -848,14 +867,14 @@ CREATE TABLE IF NOT EXISTS "settings" (
|
|||
CREATE TABLE IF NOT EXISTS "mappings" (
|
||||
"id" INTEGER PRIMARY KEY NOT NULL,
|
||||
"type" INTEGER NOT NULL,
|
||||
"name" VARCHAR NOT NULL,
|
||||
"name_hash" BLOB NOT NULL,
|
||||
"value" BLOB NOT NULL,
|
||||
"txid" BLOB NOT NULL,
|
||||
"prev_txid" BLOB NOT NULL,
|
||||
"register_height" INTEGER NOT NULL,
|
||||
"owner_id" INTEGER NOT NULL REFERENCES "owner" ("id")
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "name_type_id" ON mappings("name", "type");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "name_hash_type_id" ON mappings("name_hash", "type");
|
||||
)";
|
||||
|
||||
char *table_err_msg = nullptr;
|
||||
|
@ -880,13 +899,13 @@ bool name_system_db::init(cryptonote::network_type nettype, sqlite3 *db, uint64_
|
|||
|
||||
char constexpr GET_MAPPINGS_BY_OWNER_SQL[] = R"(SELECT * FROM "mappings" JOIN "owner" ON "mappings"."owner_id" = "owner"."id" WHERE "public_key" = ?)";
|
||||
char constexpr GET_MAPPINGS_ON_HEIGHT_AND_NEWER_SQL[] = R"(SELECT * FROM "mappings" JOIN "owner" on "mappings"."owner_id" = "owner"."id" WHERE "register_height" >= ?)";
|
||||
char constexpr GET_MAPPING_SQL[] = R"(SELECT * FROM "mappings" JOIN "owner" on "mappings"."owner_id" = "owner"."id" WHERE "type" = ? AND "name" = ?)";
|
||||
char constexpr GET_MAPPING_SQL[] = R"(SELECT * FROM "mappings" JOIN "owner" on "mappings"."owner_id" = "owner"."id" WHERE "type" = ? AND "name_hash" = ?)";
|
||||
char constexpr GET_OWNER_BY_ID_SQL[] = R"(SELECT * FROM "owner" WHERE "id" = ?)";
|
||||
char constexpr GET_OWNER_BY_KEY_SQL[] = R"(SELECT * FROM "owner" WHERE "public_key" = ?)";
|
||||
char constexpr GET_SETTINGS_SQL[] = R"(SELECT * FROM "settings" WHERE "id" = 1)";
|
||||
char constexpr PRUNE_MAPPINGS_SQL[] = R"(DELETE FROM "mappings" WHERE "register_height" >= ?)";
|
||||
char constexpr PRUNE_OWNERS_SQL[] = R"(DELETE FROM "owner" WHERE "id" NOT IN (SELECT "owner_id" FROM "mappings"))";
|
||||
char constexpr SAVE_MAPPING_SQL[] = R"(INSERT OR REPLACE INTO "mappings" ("type", "name", "value", "txid", "prev_txid", "register_height", "owner_id") VALUES (?,?,?,?,?,?,?))";
|
||||
char constexpr SAVE_MAPPING_SQL[] = R"(INSERT OR REPLACE INTO "mappings" ("type", "name_hash", "value", "txid", "prev_txid", "register_height", "owner_id") VALUES (?,?,?,?,?,?,?))";
|
||||
char constexpr SAVE_OWNER_SQL[] = R"(INSERT INTO "owner" ("public_key") VALUES (?);)";
|
||||
char constexpr SAVE_SETTINGS_SQL[] = R"(INSERT OR REPLACE INTO "settings" ("id", "top_height", "top_hash", "version") VALUES (1,?,?,?))";
|
||||
|
||||
|
@ -995,7 +1014,7 @@ static bool add_lns_entry(lns::name_system_db &lns_db, uint64_t height, cryptono
|
|||
|
||||
if (!lns_db.save_owner(entry.owner, &owner_id))
|
||||
{
|
||||
LOG_PRINT_L1("Failed to save LNS owner to DB tx: " << tx_hash << ", type: " << entry.type << ", name: " << entry.name << ", owner: " << entry.owner);
|
||||
LOG_PRINT_L1("Failed to save LNS owner to DB tx: " << tx_hash << ", type: " << entry.type << ", name_hash: " << entry.name_hash << ", owner: " << entry.owner);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1003,7 +1022,7 @@ static bool add_lns_entry(lns::name_system_db &lns_db, uint64_t height, cryptono
|
|||
|
||||
if (!lns_db.save_mapping(tx_hash, entry, height, owner_id))
|
||||
{
|
||||
LOG_PRINT_L1("Failed to save LNS entry to DB tx: " << tx_hash << ", type: " << entry.type << ", name: " << entry.name << ", owner: " << entry.owner);
|
||||
LOG_PRINT_L1("Failed to save LNS entry to DB tx: " << tx_hash << ", type: " << entry.type << ", name_hash: " << entry.name_hash << ", owner: " << entry.owner);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1155,7 +1174,7 @@ bool name_system_db::save_mapping(crypto::hash const &tx_hash, cryptonote::tx_ex
|
|||
{
|
||||
sqlite3_stmt *statement = save_mapping_sql;
|
||||
sqlite3_bind_int (statement, static_cast<int>(mapping_record_row::type), static_cast<uint16_t>(src.type));
|
||||
sqlite3_bind_text (statement, static_cast<int>(mapping_record_row::name), src.name.data(), src.name.size(), nullptr /*destructor*/);
|
||||
sqlite3_bind_blob (statement, static_cast<int>(mapping_record_row::name_hash), src.name_hash.data, sizeof(src.name_hash), nullptr /*destructor*/);
|
||||
sqlite3_bind_blob (statement, static_cast<int>(mapping_record_row::value), src.value.data(), src.value.size(), nullptr /*destructor*/);
|
||||
sqlite3_bind_blob (statement, static_cast<int>(mapping_record_row::txid), tx_hash.data, sizeof(tx_hash), nullptr /*destructor*/);
|
||||
sqlite3_bind_blob (statement, static_cast<int>(mapping_record_row::prev_txid), src.prev_txid.data, sizeof(src.prev_txid), nullptr /*destructor*/);
|
||||
|
@ -1213,26 +1232,26 @@ owner_record name_system_db::get_owner_by_id(int64_t owner_id) const
|
|||
return result;
|
||||
}
|
||||
|
||||
mapping_record name_system_db::get_mapping(mapping_type type, std::string const &name) const
|
||||
mapping_record name_system_db::get_mapping(mapping_type type, crypto::hash const &name_hash) const
|
||||
{
|
||||
sqlite3_stmt *statement = get_mapping_sql;
|
||||
sqlite3_clear_bindings(statement);
|
||||
sqlite3_bind_int(statement, 1 /*sql param index*/, static_cast<int>(type));
|
||||
sqlite3_bind_text(statement, 2 /*sql param index*/, name.data(), name.size(), nullptr /*destructor*/);
|
||||
sqlite3_bind_int(statement, 1 /*sql param index*/, static_cast<uint16_t>(type));
|
||||
sqlite3_bind_blob(statement, 2 /*sql param index*/, name_hash.data, sizeof(name_hash), nullptr /*destructor*/);
|
||||
|
||||
mapping_record result = {};
|
||||
result.loaded = sql_run_statement(nettype, lns_sql_type::get_mapping, statement, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<mapping_record> name_system_db::get_mappings(std::vector<uint16_t> const &types, std::string const &name) const
|
||||
std::vector<mapping_record> name_system_db::get_mappings(std::vector<uint16_t> const &types, crypto::hash const &name_hash) const
|
||||
{
|
||||
std::string sql_statement;
|
||||
// Generate string statement
|
||||
|
||||
if (types.size())
|
||||
{
|
||||
char constexpr SQL_PREFIX[] = R"(SELECT * FROM "mappings" JOIN "owner" ON "mappings"."owner_id" = "owner"."id" WHERE "name" = ? AND "type" in ()";
|
||||
char constexpr SQL_PREFIX[] = R"(SELECT * FROM "mappings" JOIN "owner" ON "mappings"."owner_id" = "owner"."id" WHERE "name_hash" = ? AND "type" in ()";
|
||||
char constexpr SQL_SUFFIX[] = R"())";
|
||||
|
||||
std::stringstream stream;
|
||||
|
@ -1258,7 +1277,7 @@ std::vector<mapping_record> name_system_db::get_mappings(std::vector<uint16_t> c
|
|||
|
||||
// Bind parameters statements
|
||||
int sql_param_index = 1;
|
||||
sqlite3_bind_text(statement, sql_param_index++, name.data(), name.size(), nullptr /*destructor*/);
|
||||
sqlite3_bind_blob(statement, sql_param_index++, name_hash.data, sizeof(name_hash), nullptr /*destructor*/);
|
||||
for (auto type : types)
|
||||
sqlite3_bind_int(statement, sql_param_index++, type);
|
||||
assert((sql_param_index - 1) == static_cast<int>(1 /*name*/ + types.size()));
|
||||
|
|
|
@ -65,7 +65,8 @@ bool validate_lns_name(mapping_type type, std::string const &name, std::
|
|||
// blob: if set, validate_lns_value will convert the value into the binary format suitable for storing into the LNS DB.
|
||||
bool validate_lns_value(cryptonote::network_type nettype, mapping_type type, std::string const &value, lns_value *blob = nullptr, std::string *reason = nullptr);
|
||||
bool validate_lns_value_binary(mapping_type type, std::string const &value, std::string *reason = nullptr);
|
||||
bool validate_mapping_type(std::string const &mapping_type_str, lns::mapping_type *mapping_type, std::string *reason);
|
||||
bool validate_mapping_type(std::string const &type, lns::mapping_type *mapping_type, std::string *reason);
|
||||
crypto::hash name_to_hash(std::string const &name);
|
||||
|
||||
struct owner_record
|
||||
{
|
||||
|
@ -98,7 +99,7 @@ struct mapping_record
|
|||
|
||||
bool loaded;
|
||||
mapping_type type;
|
||||
std::string name;
|
||||
crypto::hash name_hash;
|
||||
std::string value;
|
||||
uint64_t register_height;
|
||||
int64_t owner_id;
|
||||
|
@ -123,8 +124,8 @@ struct name_system_db
|
|||
|
||||
owner_record get_owner_by_key (crypto::ed25519_public_key const &key) const;
|
||||
owner_record get_owner_by_id (int64_t owner_id) const;
|
||||
mapping_record get_mapping (mapping_type type, std::string const &name) const;
|
||||
std::vector<mapping_record> get_mappings (std::vector<uint16_t> const &types, std::string const &name) const;
|
||||
mapping_record get_mapping (mapping_type type, crypto::hash const &name_hash) const;
|
||||
std::vector<mapping_record> get_mappings (std::vector<uint16_t> const &types, crypto::hash const &name) const;
|
||||
std::vector<mapping_record> get_mappings_by_owner (crypto::ed25519_public_key const &key) const;
|
||||
std::vector<mapping_record> get_mappings_by_owners(std::vector<crypto::ed25519_public_key> const &keys) const;
|
||||
settings_record get_settings () const;
|
||||
|
|
|
@ -238,7 +238,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
|
||||
if (data.type == pool_data.type && data.name == pool_data.name)
|
||||
if (data.type == pool_data.type && data.name_hash == pool_data.name_hash)
|
||||
{
|
||||
LOG_PRINT_L1("New TX: " << get_transaction_hash(tx) << ", has TX: " << get_transaction_hash(pool_tx) << " from the pool that is requesting the same LNS entry already.");
|
||||
return true;
|
||||
|
|
|
@ -3402,7 +3402,8 @@ namespace cryptonote
|
|||
if (exceeds_quantity_limit(ctx, error_resp, m_restricted, request.types.size(), COMMAND_RPC_GET_LNS_NAMES_TO_OWNERS::MAX_TYPE_REQUEST_ENTRIES, "types"))
|
||||
return false;
|
||||
|
||||
std::vector<lns::mapping_record> records = db.get_mappings(request.types, request.name);
|
||||
crypto::hash name_hash = lns::name_to_hash(request.name);
|
||||
std::vector<lns::mapping_record> records = db.get_mappings(request.types, name_hash);
|
||||
res.entries.reserve(records.size());
|
||||
for (auto const &record : records)
|
||||
{
|
||||
|
@ -3463,7 +3464,7 @@ namespace cryptonote
|
|||
|
||||
entry.request_index = it->second;
|
||||
entry.type = static_cast<uint16_t>(mapping.type);
|
||||
entry.name = mapping.name;
|
||||
entry.name_hash = epee::string_tools::pod_to_hex(mapping.name_hash);
|
||||
entry.value = extract_lns_mapping_value(mapping);
|
||||
entry.register_height = mapping.register_height;
|
||||
entry.txid = epee::string_tools::pod_to_hex(mapping.txid);
|
||||
|
|
|
@ -3527,14 +3527,14 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
|
|||
{
|
||||
uint64_t request_index; // The index in request's `entries` array that was resolved via Loki Name Service.
|
||||
uint16_t type; // The category the Loki Name Service entry belongs to, currently only Session whose value is 0.
|
||||
std::string name; // The name purchased via Loki Name Service
|
||||
std::string value; // The value that the name maps to
|
||||
std::string name_hash; // The hash of the name that the owner purchased via Loki Name Service.
|
||||
std::string value; // The value that the name maps to.
|
||||
uint64_t register_height; // The height that this Loki Name Service entry was purchased on the Blockchain.
|
||||
std::string txid; // The txid of who purchases the mapping, null hash if not applicable
|
||||
std::string prev_txid; // The previous txid that purchased the mapping, null hash if not applicable.
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(type)
|
||||
KV_SERIALIZE(name)
|
||||
KV_SERIALIZE(name_hash)
|
||||
KV_SERIALIZE(value)
|
||||
KV_SERIALIZE(register_height)
|
||||
KV_SERIALIZE(txid)
|
||||
|
|
|
@ -271,7 +271,7 @@ namespace
|
|||
const char* USAGE_PRINT_LOCKED_STAKES("print_locked_stakes");
|
||||
const char* USAGE_BUY_LNS_MAPPING("buy_lns_mapping [index=<N1>[,<N2>,...]] [<priority>] [owner] \"<name>\" <value>");
|
||||
const char* USAGE_UPDATE_LNS_MAPPING("update_lns_mapping [index=<N1>[,<N2>,...]] [<priority>] \"<name>\" <value> [<signature>]");
|
||||
const char* USAGE_PRINT_LNS_OWNERS_TO_NAMES("print_lns_owners_to_names [<64 hex character ed25519 public key>]");
|
||||
const char* USAGE_PRINT_LNS_OWNERS_TO_NAME_HASHES("print_lns_owners_to_name_hashes [<64 hex character ed25519 public key>]");
|
||||
const char* USAGE_PRINT_LNS_NAME_TO_OWNERS("print_lns_name_to_owners [type=<N1|all>[,<N2>...]] \"name\"");
|
||||
|
||||
#if defined (LOKI_ENABLE_INTEGRATION_TEST_HOOKS)
|
||||
|
@ -3113,10 +3113,10 @@ Pending or Failed: "failed"|"pending", "out", Time, Amount*, Transaction Hash,
|
|||
tr(USAGE_UPDATE_LNS_MAPPING),
|
||||
tr(stream.str().c_str()));
|
||||
|
||||
m_cmd_binder.set_handler("print_lns_owners_to_names",
|
||||
boost::bind(&simple_wallet::print_lns_owners_to_names, this, _1),
|
||||
tr(USAGE_PRINT_LNS_OWNERS_TO_NAMES),
|
||||
tr("Query the Loki Name Service names that the keys have purchased. If no keys are specified, it defaults to the current wallet."));
|
||||
m_cmd_binder.set_handler("print_lns_owners_to_name_hashes",
|
||||
boost::bind(&simple_wallet::print_lns_owners_to_name_hashes, this, _1),
|
||||
tr(USAGE_PRINT_LNS_OWNERS_TO_NAME_HASHES),
|
||||
tr("Query the Loki Name Service names that the owners have purchased. If no keys are specified, it defaults to the current wallet."));
|
||||
|
||||
m_cmd_binder.set_handler("print_lns_name_to_owners",
|
||||
boost::bind(&simple_wallet::print_lns_name_to_owners, this, _1),
|
||||
|
@ -6614,7 +6614,7 @@ bool simple_wallet::print_lns_name_to_owners(const std::vector<std::string>& arg
|
|||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool simple_wallet::print_lns_owners_to_names(const std::vector<std::string>& args)
|
||||
bool simple_wallet::print_lns_owners_to_name_hashes(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!try_connect_to_daemon())
|
||||
return false;
|
||||
|
@ -6675,7 +6675,7 @@ bool simple_wallet::print_lns_owners_to_names(const std::vector<std::string>& ar
|
|||
}
|
||||
}
|
||||
|
||||
tools::msg_writer() << "owner=" << *owner << ", type=" << static_cast<lns::mapping_type>(entry.type) << ", height=" << entry.register_height << ", name=\"" << entry.name << "\", value=" << entry.value << ", prev_txid=" << entry.prev_txid;
|
||||
tools::msg_writer() << "owner=" << *owner << ", type=" << entry.type << ", height=" << entry.register_height << ", name_hash=\"" << entry.name_hash << "\", value=" << entry.value << ", prev_txid=" << entry.prev_txid;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ namespace cryptonote
|
|||
bool query_locked_stakes(bool print_result);
|
||||
bool buy_lns_mapping(const std::vector<std::string> &args);
|
||||
bool update_lns_mapping(const std::vector<std::string> &args);
|
||||
bool print_lns_owners_to_names(const std::vector<std::string> &args);
|
||||
bool print_lns_owners_to_name_hashes(const std::vector<std::string> &args);
|
||||
bool print_lns_name_to_owners(const std::vector<std::string> &args);
|
||||
|
||||
enum class sweep_type_t { stake, register_stake, all_or_below, single };
|
||||
|
|
|
@ -8469,7 +8469,7 @@ static bool prepare_tx_extra_loki_name_system_values(cryptonote::network_type ne
|
|||
|
||||
if (response.size())
|
||||
{
|
||||
crypto::hash txid_hash;
|
||||
crypto::hash txid_hash = {};
|
||||
if (epee::string_tools::hex_to_pod(response[0].txid, txid_hash))
|
||||
{
|
||||
prev_txid = txid_hash;
|
||||
|
@ -8515,7 +8515,7 @@ std::vector<wallet2::pending_tx> wallet2::create_buy_lns_mapping_tx(lns::mapping
|
|||
return {};
|
||||
|
||||
std::vector<uint8_t> extra;
|
||||
auto entry = cryptonote::tx_extra_loki_name_system::make_buy(pkey, type, name, std::string(reinterpret_cast<char const *>(value_blob.buffer.data()), value_blob.len), prev_txid);
|
||||
auto entry = cryptonote::tx_extra_loki_name_system::make_buy(pkey, type, lns::name_to_hash(name), std::string(reinterpret_cast<char const *>(value_blob.buffer.data()), value_blob.len), prev_txid);
|
||||
add_loki_name_system_to_tx_extra(extra, entry);
|
||||
|
||||
boost::optional<uint8_t> hf_version = get_hard_fork_version();
|
||||
|
@ -8588,7 +8588,7 @@ std::vector<wallet2::pending_tx> wallet2::create_update_lns_mapping_tx(lns::mapp
|
|||
}
|
||||
|
||||
std::vector<uint8_t> extra;
|
||||
auto entry = cryptonote::tx_extra_loki_name_system::make_update(signature_binary, type, name, std::string(reinterpret_cast<char const *>(value_blob.buffer.data()), value_blob.len), prev_txid);
|
||||
auto entry = cryptonote::tx_extra_loki_name_system::make_update(signature_binary, type, lns::name_to_hash(name), std::string(reinterpret_cast<char const *>(value_blob.buffer.data()), value_blob.len), prev_txid);
|
||||
add_loki_name_system_to_tx_extra(extra, entry);
|
||||
|
||||
boost::optional<uint8_t> hf_version = get_hard_fork_version();
|
||||
|
|
|
@ -519,7 +519,7 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx(crypton
|
|||
crypto::ed25519_public_key const *owner,
|
||||
uint64_t burn) const
|
||||
{
|
||||
crypto::ed25519_public_key pkey;
|
||||
crypto::ed25519_public_key pkey = {};
|
||||
if (owner)
|
||||
{
|
||||
pkey = *owner;
|
||||
|
@ -527,7 +527,7 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx(crypton
|
|||
else
|
||||
{
|
||||
crypto::ed25519_secret_key skey;
|
||||
crypto_sign_ed25519_seed_keypair(pkey.data, skey.data, reinterpret_cast<const unsigned char *>(src.get_keys().m_spend_secret_key.data));
|
||||
crypto_sign_ed25519_seed_keypair(pkey.data, skey.data, reinterpret_cast<const unsigned char *>(&src.get_keys().m_spend_secret_key));
|
||||
}
|
||||
|
||||
cryptonote::block const &head = top().block;
|
||||
|
@ -536,12 +536,13 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx(crypton
|
|||
if (burn == LNS_AUTO_BURN)
|
||||
burn = lns::burn_needed(new_hf_version, type);
|
||||
|
||||
crypto::hash name_hash = lns::name_to_hash(name);
|
||||
crypto::hash prev_txid = crypto::null_hash;
|
||||
if (lns::mapping_record mapping = lns_db_.get_mapping(type, name))
|
||||
if (lns::mapping_record mapping = lns_db_.get_mapping(type, name_hash))
|
||||
prev_txid = mapping.txid;
|
||||
|
||||
std::vector<uint8_t> extra;
|
||||
cryptonote::tx_extra_loki_name_system data = cryptonote::tx_extra_loki_name_system::make_buy(pkey, type, name, value, prev_txid);
|
||||
cryptonote::tx_extra_loki_name_system data = cryptonote::tx_extra_loki_name_system::make_buy(pkey, type, name_hash, 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 = {};
|
||||
|
@ -561,7 +562,8 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx_update(
|
|||
crypto::ed25519_signature *signature,
|
||||
bool use_asserts) const
|
||||
{
|
||||
lns::mapping_record mapping = lns_db_.get_mapping(type, name);
|
||||
crypto::hash name_hash = lns::name_to_hash(name);
|
||||
lns::mapping_record mapping = lns_db_.get_mapping(type, name_hash);
|
||||
crypto::hash prev_txid = mapping.txid;
|
||||
if (use_asserts) assert(mapping);
|
||||
|
||||
|
@ -578,7 +580,7 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx_update(
|
|||
}
|
||||
|
||||
std::vector<uint8_t> extra;
|
||||
cryptonote::tx_extra_loki_name_system data = cryptonote::tx_extra_loki_name_system::make_update(*signature, type, name, value, prev_txid);
|
||||
cryptonote::tx_extra_loki_name_system data = cryptonote::tx_extra_loki_name_system::make_update(*signature, type, name_hash, value, prev_txid);
|
||||
cryptonote::add_loki_name_system_to_tx_extra(extra, data);
|
||||
|
||||
cryptonote::block const &head = top().block;
|
||||
|
|
|
@ -1067,6 +1067,7 @@ bool loki_name_system_expiration::generate(std::vector<test_event_entry> &events
|
|||
|
||||
uint64_t height_of_lns_entry = gen.height();
|
||||
uint64_t expected_expiry_block = height_of_lns_entry + lns::expiry_blocks(cryptonote::FAKECHAIN, mapping_type, nullptr);
|
||||
crypto::hash name_hash = lns::name_to_hash(name);
|
||||
|
||||
loki_register_callback(events, "check_lns_entries", [=](cryptonote::core &c, size_t ev_index)
|
||||
{
|
||||
|
@ -1078,10 +1079,10 @@ bool loki_name_system_expiration::generate(std::vector<test_event_entry> &events
|
|||
CHECK_EQ(owner.id, 1);
|
||||
CHECK_EQ(miner_key.ed_key, owner.key);
|
||||
|
||||
lns::mapping_record mappings = lns_db.get_mapping(mapping_type, name);
|
||||
lns::mapping_record mappings = lns_db.get_mapping(mapping_type, name_hash);
|
||||
CHECK_EQ(mappings.loaded, true);
|
||||
CHECK_EQ(mappings.type, mapping_type);
|
||||
CHECK_EQ(mappings.name, name);
|
||||
CHECK_EQ(mappings.name_hash, name_hash);
|
||||
CHECK_EQ(mappings.value, miner_key.lokinet_value);
|
||||
CHECK_EQ(mappings.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings.owner_id, owner.id);
|
||||
|
@ -1103,11 +1104,11 @@ bool loki_name_system_expiration::generate(std::vector<test_event_entry> &events
|
|||
CHECK_EQ(owner.id, 1);
|
||||
CHECK_EQ(miner_key.ed_key, owner.key);
|
||||
|
||||
lns::mapping_record mappings = lns_db.get_mapping(mapping_type, name);
|
||||
lns::mapping_record mappings = lns_db.get_mapping(mapping_type, name_hash);
|
||||
CHECK_EQ(mappings.loaded, true);
|
||||
CHECK_EQ(mappings.active(cryptonote::FAKECHAIN, blockchain_height), false);
|
||||
CHECK_EQ(mappings.type, mapping_type);
|
||||
CHECK_EQ(mappings.name, name);
|
||||
CHECK_EQ(mappings.name_hash, name_hash);
|
||||
CHECK_EQ(mappings.value, miner_key.lokinet_value);
|
||||
CHECK_EQ(mappings.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings.owner_id, owner.id);
|
||||
|
@ -1192,8 +1193,8 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
|
|||
|
||||
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::session))
|
||||
{
|
||||
CHECK_EQ(records[0].name, session_name1);
|
||||
CHECK_EQ(records[1].name, session_name2);
|
||||
CHECK_EQ(records[0].name_hash, lns::name_to_hash(session_name1));
|
||||
CHECK_EQ(records[1].name_hash, lns::name_to_hash(session_name2));
|
||||
CHECK_EQ(records[0].register_height, session_height);
|
||||
CHECK_EQ(records[1].register_height, session_height);
|
||||
CHECK_EQ(records[0].value, bob_key.session_value);
|
||||
|
@ -1204,8 +1205,8 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
|
|||
|
||||
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year))
|
||||
{
|
||||
CHECK_EQ(records[2].name, lokinet_name1);
|
||||
CHECK_EQ(records[3].name, lokinet_name2);
|
||||
CHECK_EQ(records[2].name_hash, lns::name_to_hash(lokinet_name1));
|
||||
CHECK_EQ(records[3].name_hash, lns::name_to_hash(lokinet_name2));
|
||||
CHECK_EQ(records[2].register_height, lokinet_height);
|
||||
CHECK_EQ(records[3].register_height, lokinet_height);
|
||||
CHECK_EQ(records[2].value, bob_key.lokinet_value);
|
||||
|
@ -1216,8 +1217,8 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
|
|||
|
||||
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::wallet))
|
||||
{
|
||||
CHECK_EQ(records[4].name, wallet_name1);
|
||||
CHECK_EQ(records[5].name, wallet_name2);
|
||||
CHECK_EQ(records[4].name_hash, lns::name_to_hash(wallet_name1));
|
||||
CHECK_EQ(records[5].name_hash, lns::name_to_hash(wallet_name2));
|
||||
CHECK_EQ(records[4].register_height, wallet_height);
|
||||
CHECK_EQ(records[5].register_height, wallet_height);
|
||||
CHECK_EQ(records[4].value, bob_key.wallet_value);
|
||||
|
@ -1293,7 +1294,7 @@ bool loki_name_system_get_mappings_by_owners::generate(std::vector<test_event_en
|
|||
return lhs.register_height < rhs.register_height;
|
||||
});
|
||||
CHECK_EQ(records[0].type, lns::mapping_type::session);
|
||||
CHECK_EQ(records[0].name, session_name1);
|
||||
CHECK_EQ(records[0].name_hash, lns::name_to_hash(session_name1));
|
||||
CHECK_EQ(records[0].value, bob_key.session_value);
|
||||
CHECK_EQ(records[0].register_height, session_height1);
|
||||
CHECK_EQ(records[0].prev_txid, crypto::null_hash);
|
||||
|
@ -1301,7 +1302,7 @@ bool loki_name_system_get_mappings_by_owners::generate(std::vector<test_event_en
|
|||
CHECK_EQ(records[0].owner, bob_key.ed_key);
|
||||
|
||||
CHECK_EQ(records[1].type, lns::mapping_type::session);
|
||||
CHECK_EQ(records[1].name, session_name2);
|
||||
CHECK_EQ(records[1].name_hash, lns::name_to_hash(session_name2));
|
||||
CHECK_EQ(records[1].value, bob_key.session_value);
|
||||
CHECK_EQ(records[1].register_height, session_height2);
|
||||
CHECK_EQ(records[1].prev_txid, crypto::null_hash);
|
||||
|
@ -1309,7 +1310,7 @@ bool loki_name_system_get_mappings_by_owners::generate(std::vector<test_event_en
|
|||
CHECK_EQ(records[1].owner, bob_key.ed_key);
|
||||
|
||||
CHECK_EQ(records[2].type, lns::mapping_type::session);
|
||||
CHECK_EQ(records[2].name, session_name3);
|
||||
CHECK_EQ(records[2].name_hash, lns::name_to_hash(session_name3));
|
||||
CHECK_EQ(records[2].value, miner_key.session_value);
|
||||
CHECK_EQ(records[2].register_height, session_height3);
|
||||
CHECK_EQ(records[2].prev_txid, crypto::null_hash);
|
||||
|
@ -1354,10 +1355,12 @@ bool loki_name_system_get_mappings::generate(std::vector<test_event_entry> &even
|
|||
{
|
||||
DEFINE_TESTS_ERROR_CONTEXT("check_lns_entries");
|
||||
lns::name_system_db const &lns_db = c.get_blockchain_storage().name_system_db();
|
||||
std::vector<lns::mapping_record> records = lns_db.get_mappings({static_cast<uint16_t>(lns::mapping_type::session)}, session_name1);
|
||||
|
||||
crypto::hash session_name_hash = lns::name_to_hash(session_name1);
|
||||
std::vector<lns::mapping_record> records = lns_db.get_mappings({static_cast<uint16_t>(lns::mapping_type::session)}, session_name_hash);
|
||||
CHECK_EQ(records.size(), 1);
|
||||
CHECK_EQ(records[0].type, lns::mapping_type::session);
|
||||
CHECK_EQ(records[0].name, session_name1);
|
||||
CHECK_EQ(records[0].name_hash, session_name_hash);
|
||||
CHECK_EQ(records[0].value, bob_key.session_value);
|
||||
CHECK_EQ(records[0].register_height, session_height);
|
||||
CHECK_EQ(records[0].prev_txid, crypto::null_hash);
|
||||
|
@ -1427,20 +1430,21 @@ bool loki_name_system_handles_duplicate_in_lns_db::generate(std::vector<test_eve
|
|||
CHECK_EQ(owner.id, 1);
|
||||
CHECK_EQ(miner_key.ed_key, owner.key);
|
||||
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::session, session_name);
|
||||
crypto::hash session_name_hash = lns::name_to_hash(session_name);
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::session, session_name_hash);
|
||||
CHECK_EQ(mappings.loaded, true);
|
||||
CHECK_EQ(mappings.type, lns::mapping_type::session);
|
||||
CHECK_EQ(mappings.name, session_name);
|
||||
CHECK_EQ(mappings.name_hash, session_name_hash);
|
||||
CHECK_EQ(mappings.value, bob_key.session_value);
|
||||
CHECK_EQ(mappings.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings.owner_id, owner.id);
|
||||
|
||||
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year))
|
||||
{
|
||||
lns::mapping_record mappings2 = lns_db.get_mapping(lns::mapping_type::lokinet_1year, session_name);
|
||||
lns::mapping_record mappings2 = lns_db.get_mapping(lns::mapping_type::lokinet_1year, session_name_hash);
|
||||
CHECK_EQ(mappings2.loaded, true);
|
||||
CHECK_EQ(mappings2.type, lns::mapping_type::lokinet_1year);
|
||||
CHECK_EQ(mappings2.name, session_name);
|
||||
CHECK_EQ(mappings2.name_hash, session_name_hash);
|
||||
CHECK_EQ(mappings2.value, miner_key.lokinet_value);
|
||||
CHECK_EQ(mappings2.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings2.owner_id, owner.id);
|
||||
|
@ -1448,10 +1452,10 @@ bool loki_name_system_handles_duplicate_in_lns_db::generate(std::vector<test_eve
|
|||
|
||||
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), custom_type))
|
||||
{
|
||||
lns::mapping_record mappings3 = lns_db.get_mapping(custom_type, session_name);
|
||||
lns::mapping_record mappings3 = lns_db.get_mapping(custom_type, session_name_hash);
|
||||
CHECK_EQ(mappings3.loaded, true);
|
||||
CHECK_EQ(mappings3.type, custom_type);
|
||||
CHECK_EQ(mappings3.name, session_name);
|
||||
CHECK_EQ(mappings3.name_hash, session_name_hash);
|
||||
CHECK_EQ(mappings3.value, bob_key.session_value);
|
||||
CHECK_EQ(mappings3.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings3.owner_id, owner.id);
|
||||
|
@ -1541,21 +1545,14 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
|
|||
valid_data.owner = miner_key.ed_key;
|
||||
valid_data.type = lns::mapping_type::wallet;
|
||||
valid_data.value = miner_key.wallet_value;
|
||||
valid_data.name = "my_lns_name";
|
||||
valid_data.name_hash = lns::name_to_hash("my_lns_name");
|
||||
|
||||
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::wallet))
|
||||
{
|
||||
// Blockchain name too long
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = std::string(lns::WALLET_NAME_MAX + 1, 'A');
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Blockchain) Wallet to name in LNS too long");
|
||||
}
|
||||
|
||||
// Blockchain name empty
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = {};
|
||||
data.name_hash = {};
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Blockchain) Empty wallet name in LNS is invalid");
|
||||
}
|
||||
|
||||
|
@ -1570,18 +1567,10 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
|
|||
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
|
||||
{
|
||||
valid_data.type = lns::mapping_type::lokinet_1year;
|
||||
// Lokinet domain name too long
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = std::string(lns::LOKINET_DOMAIN_NAME_MAX, 'A');
|
||||
data.name += ".loki";
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Lokinet) Domain name in LNS too long");
|
||||
}
|
||||
|
||||
// Lokinet domain name empty
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = {};
|
||||
data.name_hash = {};
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Lokinet) Empty domain name in LNS is invalid");
|
||||
}
|
||||
|
||||
|
@ -1629,7 +1618,7 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
|
|||
|
||||
// Session value too short
|
||||
// We added valid tx prior, we should update name to avoid conflict names in session land and test other invalid params
|
||||
valid_data.name = "new_friendly_name";
|
||||
valid_data.name_hash = lns::name_to_hash("new_friendly_name");
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.value = std::string(lns::SESSION_PUBLIC_KEY_BINARY_LENGTH * 2 - 1, 'A');
|
||||
|
@ -1643,18 +1632,11 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
|
|||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Session) User id, value too long");
|
||||
}
|
||||
|
||||
// Session name too long
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = std::string(lns::SESSION_DISPLAY_NAME_MAX + 1, 'A');
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Session) User id, name too long");
|
||||
}
|
||||
|
||||
// Session name empty
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = {};
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Session) User id, name too long");
|
||||
data.name_hash = {};
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Session) Name empty");
|
||||
}
|
||||
|
||||
auto custom_type = static_cast<lns::mapping_type>(1111);
|
||||
|
@ -1666,7 +1648,7 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
|
|||
// Generic name empty
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = {};
|
||||
data.name_hash = {};
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Generic) Name empty");
|
||||
}
|
||||
|
||||
|
@ -1680,7 +1662,7 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
|
|||
// Generic name too long
|
||||
{
|
||||
cryptonote::tx_extra_loki_name_system data = valid_data;
|
||||
data.name = std::string(lns::GENERIC_NAME_MAX + 1, 'A');
|
||||
data.name_hash = lns::name_to_hash(std::string(lns::GENERIC_NAME_MAX + 1, 'A'));
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data, false, "(Generic) Name empty");
|
||||
}
|
||||
|
||||
|
@ -1765,19 +1747,19 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
|
|||
{
|
||||
if (record.type == lns::mapping_type::session)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_session_name1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_session_name1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.session_value);
|
||||
}
|
||||
else if (record.type == lns::mapping_type::lokinet_1year)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_lokinet_domain1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_lokinet_domain1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.lokinet_value);
|
||||
}
|
||||
else if (record.type == lns::mapping_type::wallet)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_wallet_name1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_wallet_name1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.wallet_value);
|
||||
}
|
||||
|
@ -1823,19 +1805,19 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
|
|||
{
|
||||
if (record.type == lns::mapping_type::session)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_session_name1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_session_name1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.session_value);
|
||||
}
|
||||
else if (record.type == lns::mapping_type::lokinet_1year)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_lokinet_domain1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_lokinet_domain1));
|
||||
CHECK_EQ(record.register_height, second_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.lokinet_value);
|
||||
}
|
||||
else if (record.type == lns::mapping_type::wallet)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_wallet_name1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_wallet_name1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.wallet_value);
|
||||
}
|
||||
|
@ -1850,7 +1832,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
|
|||
{
|
||||
std::vector<lns::mapping_record> records = lns_db.get_mappings_by_owner(bob_key.ed_key);
|
||||
CHECK_EQ(records.size(), 1);
|
||||
CHECK_EQ(records[0].name, bob_session_name1);
|
||||
CHECK_EQ(records[0].name_hash, lns::name_to_hash(bob_session_name1));
|
||||
CHECK_EQ(records[0].register_height, second_lns_height);
|
||||
CHECK_EQ(records[0].value, bob_key.session_value);
|
||||
CHECK_EQ(records[0].type, lns::mapping_type::session);
|
||||
|
@ -1892,19 +1874,19 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
|
|||
{
|
||||
if (record.type == lns::mapping_type::session)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_session_name1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_session_name1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.session_value);
|
||||
}
|
||||
else if (record.type == lns::mapping_type::lokinet_1year)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_lokinet_domain1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_lokinet_domain1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.lokinet_value);
|
||||
}
|
||||
else if (record.type == lns::mapping_type::wallet)
|
||||
{
|
||||
CHECK_EQ(record.name, miner_wallet_name1);
|
||||
CHECK_EQ(record.name_hash, lns::name_to_hash(miner_wallet_name1));
|
||||
CHECK_EQ(record.register_height, first_lns_height);
|
||||
CHECK_EQ(record.value, miner_key.wallet_value);
|
||||
}
|
||||
|
@ -1979,10 +1961,11 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
|
|||
CHECK_EQ(owner.id, 1);
|
||||
CHECK_EQ(miner_key.ed_key, owner.key);
|
||||
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
|
||||
crypto::hash name_hash = lns::name_to_hash(name);
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name_hash);
|
||||
CHECK_EQ(mappings.loaded, true);
|
||||
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
|
||||
CHECK_EQ(mappings.name, name);
|
||||
CHECK_EQ(mappings.name_hash, name_hash);
|
||||
CHECK_EQ(mappings.value, miner_key.lokinet_value);
|
||||
CHECK_EQ(mappings.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings.prev_txid, crypto::null_hash);
|
||||
|
@ -2008,10 +1991,11 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
|
|||
CHECK_EQ(owner.id, 1);
|
||||
CHECK_EQ(miner_key.ed_key, owner.key);
|
||||
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
|
||||
crypto::hash name_hash = lns::name_to_hash(name);
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name_hash);
|
||||
CHECK_EQ(mappings.loaded, true);
|
||||
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
|
||||
CHECK_EQ(mappings.name, name);
|
||||
CHECK_EQ(mappings.name_hash, name_hash);
|
||||
CHECK_EQ(mappings.value, miner_key.lokinet_value);
|
||||
CHECK_EQ(mappings.register_height, renewal_height);
|
||||
CHECK_EQ(mappings.prev_txid, prev_txid);
|
||||
|
@ -2061,37 +2045,28 @@ bool loki_name_system_name_value_max_lengths::generate(std::vector<test_event_en
|
|||
// Blockchain
|
||||
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::wallet))
|
||||
{
|
||||
data.type = lns::mapping_type::wallet;
|
||||
data.name = std::string(lns::WALLET_NAME_MAX, 'A');
|
||||
data.value = miner_key.wallet_value;
|
||||
data.type = lns::mapping_type::wallet;
|
||||
data.name_hash = lns::name_to_hash(std::string(lns::WALLET_NAME_MAX, 'A'));
|
||||
data.value = miner_key.wallet_value;
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data);
|
||||
}
|
||||
|
||||
// Lokinet
|
||||
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
|
||||
{
|
||||
data.type = lns::mapping_type::lokinet_1year;
|
||||
data.name = "doyle.loki";
|
||||
data.value = std::string(lns::LOKINET_ADDRESS_BINARY_LENGTH, 'a');
|
||||
data.type = lns::mapping_type::lokinet_1year;
|
||||
data.name_hash = lns::name_to_hash("doyle.loki");
|
||||
data.value = std::string(lns::LOKINET_ADDRESS_BINARY_LENGTH, 'a');
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data);
|
||||
}
|
||||
|
||||
// Session
|
||||
{
|
||||
data.type = lns::mapping_type::session;
|
||||
data.name = std::string(lns::SESSION_DISPLAY_NAME_MAX, 'A');
|
||||
data.value = std::string(lns::SESSION_PUBLIC_KEY_BINARY_LENGTH, 'a');
|
||||
data.value[0] = '0';
|
||||
data.value[1] = '5';
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data);
|
||||
}
|
||||
|
||||
// Generic
|
||||
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
|
||||
{
|
||||
data.type = static_cast<lns::mapping_type>(1111);
|
||||
data.name = std::string(lns::GENERIC_NAME_MAX, 'A');
|
||||
data.value = std::string(lns::GENERIC_VALUE_MAX, 'a');
|
||||
data.type = lns::mapping_type::session;
|
||||
data.name_hash = lns::name_to_hash(std::string(lns::SESSION_DISPLAY_NAME_MAX, 'A'));
|
||||
data.value = std::string(lns::SESSION_PUBLIC_KEY_BINARY_LENGTH, 'a');
|
||||
data.value[0] = '0';
|
||||
data.value[1] = '5';
|
||||
make_lns_tx_with_custom_extra(gen, events, miner, data);
|
||||
}
|
||||
|
||||
|
@ -2135,10 +2110,11 @@ bool loki_name_system_update_mapping_after_expiry_fails::generate(std::vector<te
|
|||
CHECK_EQ(owner.id, 1);
|
||||
CHECK_EQ(miner_key.ed_key, owner.key);
|
||||
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
|
||||
crypto::hash name_hash = lns::name_to_hash(name);
|
||||
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name_hash);
|
||||
CHECK_EQ(mappings.loaded, true);
|
||||
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
|
||||
CHECK_EQ(mappings.name, name);
|
||||
CHECK_EQ(mappings.name_hash, name_hash);
|
||||
CHECK_EQ(mappings.value, miner_key.lokinet_value);
|
||||
CHECK_EQ(mappings.register_height, height_of_lns_entry);
|
||||
CHECK_EQ(mappings.owner_id, owner.id);
|
||||
|
@ -2188,10 +2164,12 @@ bool loki_name_system_update_mapping::generate(std::vector<test_event_entry> &ev
|
|||
{
|
||||
DEFINE_TESTS_ERROR_CONTEXT("check_updated");
|
||||
lns::name_system_db const &lns_db = c.get_blockchain_storage().name_system_db();
|
||||
std::vector<lns::mapping_record> records = lns_db.get_mappings({static_cast<uint16_t>(lns::mapping_type::session)}, session_name1);
|
||||
|
||||
crypto::hash name_hash = lns::name_to_hash(session_name1);
|
||||
std::vector<lns::mapping_record> records = lns_db.get_mappings({static_cast<uint16_t>(lns::mapping_type::session)}, name_hash);
|
||||
CHECK_EQ(records.size(), 1);
|
||||
CHECK_EQ(records[0].type, lns::mapping_type::session);
|
||||
CHECK_EQ(records[0].name, session_name1);
|
||||
CHECK_EQ(records[0].name_hash, name_hash);
|
||||
CHECK_EQ(records[0].value, bob_key.session_value);
|
||||
CHECK_EQ(records[0].register_height, session_height2);
|
||||
CHECK_EQ(records[0].prev_txid, session_tx_hash1);
|
||||
|
@ -2362,7 +2340,7 @@ bool loki_name_system_wrong_version::generate(std::vector<test_event_entry> &eve
|
|||
data.owner = miner_key.ed_key;
|
||||
data.type = lns::mapping_type::session;
|
||||
data.value = miner_key.session_value;
|
||||
data.name = "my_lns_name";
|
||||
data.name_hash = lns::name_to_hash("my_lns_name");
|
||||
|
||||
uint64_t new_height = cryptonote::get_block_height(gen.top().block) + 1;
|
||||
uint8_t new_hf_version = gen.get_hf_version_at(new_height);
|
||||
|
|
Loading…
Reference in New Issue