Switching to view public key lookup in db

This commit is contained in:
Lee Clagett 2020-08-20 23:08:51 -04:00
parent 535fd2bd97
commit e99374170f
4 changed files with 12 additions and 6 deletions

View file

@ -104,8 +104,8 @@ namespace db
//! The public keys of a monero address //! The public keys of a monero address
struct account_address struct account_address
{ {
crypto::public_key spend_public; //!< Must be first for LMDB optimizations. crypto::public_key view_public; //!< Must be first for LMDB optimizations.
crypto::public_key view_public; crypto::public_key spend_public;
}; };
static_assert(sizeof(account_address) == 64, "padding in account_address"); static_assert(sizeof(account_address) == 64, "padding in account_address");
WIRE_DECLARE_OBJECT(account_address); WIRE_DECLARE_OBJECT(account_address);

View file

@ -184,7 +184,7 @@ namespace db
"accounts_by_status,id", (MDB_CREATE | MDB_DUPSORT), MONERO_SORT_BY(account, id) "accounts_by_status,id", (MDB_CREATE | MDB_DUPSORT), MONERO_SORT_BY(account, id)
}; };
constexpr const lmdb::basic_table<unsigned, account_by_address> accounts_by_address( constexpr const lmdb::basic_table<unsigned, account_by_address> accounts_by_address(
"accounts_by_address", (MDB_CREATE | MDB_DUPSORT), MONERO_COMPARE(account_by_address, address.spend_public) "accounts_by_address", (MDB_CREATE | MDB_DUPSORT), MONERO_COMPARE(account_by_address, address.view_public)
); );
constexpr const lmdb::basic_table<block_id, account_lookup> accounts_by_height( constexpr const lmdb::basic_table<block_id, account_lookup> accounts_by_height(
"accounts_by_height,id", (MDB_CREATE | MDB_DUPSORT), MONERO_SORT_BY(account_lookup, id) "accounts_by_height,id", (MDB_CREATE | MDB_DUPSORT), MONERO_SORT_BY(account_lookup, id)
@ -544,6 +544,13 @@ namespace db
return {lmdb::error(err)}; return {lmdb::error(err)};
} }
/* Database is only indexing by view public for possible CurveZMQ
authentication extensions. Verifying both public keys here - the function
takes the entire address as an argument. */
static_assert(offsetof(account_by_address, address) == 0, "unexpected field offset");
if (value.mv_size < sizeof(account_address) || std::memcmp(value.mv_data, &address, sizeof(account_address)) != 0)
return {lws::error::account_not_found};
const expect<account_lookup> lookup = const expect<account_lookup> lookup =
accounts_by_address.get_value<MONERO_FIELD(account_by_address, lookup)>(value); accounts_by_address.get_value<MONERO_FIELD(account_by_address, lookup)>(value);
if (!lookup) if (!lookup)

View file

@ -55,7 +55,7 @@ namespace db
return {lws::error::bad_address}; return {lws::error::bad_address};
return account_address{ return account_address{
info.address.m_spend_public_key, info.address.m_view_public_key info.address.m_view_public_key, info.address.m_spend_public_key
}; };
} }
} // db } // db

View file

@ -789,8 +789,7 @@ namespace lws
response.m_response_comment = "OK"; response.m_response_comment = "OK";
response.m_mime_tipe = "application/json"; response.m_mime_tipe = "application/json";
response.m_header_info.m_content_type = "application/json"; response.m_header_info.m_content_type = "application/json";
response.m_body.assign(reinterpret_cast<const char*>(body->data()), body->size()); // \TODO Remove copy here too! response.m_body.assign(reinterpret_cast<const char*>(body->data()), body->size()); // \TODO Remove copy here too!s
response.m_additional_fields.push_back({"Access-Control-Allow-Credentials", "true"});
return true; return true;
} }
}; };