db_lmdb: add version fields to serialized data

This commit is contained in:
Crypto City 2023-03-28 10:42:48 +00:00
parent 56bc673661
commit 70d07fd291

View File

@ -663,6 +663,7 @@ typedef struct mdb_cc_account_data
std::vector<uint32_t> textures_licenced;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0) // do not allow going over 1 byte without changing fast balance get/set/change
FIELD(public_key)
FIELD(pmspk)
FIELD(pmvpk)
@ -731,6 +732,7 @@ typedef struct mdb_cc_city_data
uint64_t last_allow_settlers_height;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0) // do not allow going over 1 byte without changing fast treasury get
FIELD(seed)
FIELD(treasury)
VARINT_FIELD(mayor)
@ -798,6 +800,7 @@ typedef struct mdb_cc_flag_data
std::vector<uint8_t> tiles;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(deleted)
VARINT_FIELD(owner)
VARINT_FIELD(city)
@ -952,6 +955,7 @@ typedef struct mdb_cc_custom_item_data_t
std::vector<uint32_t> role_bonus;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(creation_height)
VARINT_FIELD(creator)
VARINT_FIELD(group)
@ -979,6 +983,7 @@ typedef struct mdb_cc_event_badge_data_t
std::vector<std::pair<uint64_t, std::string>> thresholds;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
TEXT_FIELD(name)
TEXT_FIELD(desc)
TEXT_FIELD(icon)
@ -992,6 +997,7 @@ typedef struct mdb_cc_attribute_data_t
std::string description;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
TEXT_FIELD(name)
TEXT_FIELD(description)
END_SERIALIZE()
@ -1010,6 +1016,7 @@ typedef struct mdb_cc_script_data_t
std::string blob;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(owner)
FIELD(is_public)
FIELD(is_storyline)
@ -1045,6 +1052,7 @@ typedef struct mdb_cc_auction_data_t
std::vector<std::tuple<uint32_t, uint64_t, uint64_t>> bids;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(ended)
VARINT_FIELD(seller)
VARINT_FIELD(type)
@ -1078,6 +1086,7 @@ typedef struct mdb_cc_runestone_data_t
std::vector<mdb_cc_runestone_override_data_t> overrides;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(script)
TEXT_FIELD(message)
FIELD(overrides)
@ -1115,6 +1124,7 @@ typedef struct mdb_cc_whisper_data_t
std::string message;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(whisperer)
VARINT_FIELD_SIGNED(x)
VARINT_FIELD_SIGNED(y)
@ -1137,6 +1147,7 @@ typedef struct mdb_cc_background_script_data
uint32_t owner;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(script)
VARINT_FIELD(state)
VARINT_FIELD(city)
@ -1150,6 +1161,7 @@ typedef struct mdb_cc_background_scripts_data
std::vector<mdb_cc_background_script_data> background_scripts;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(background_scripts)
END_SERIALIZE()
} mdb_cc_background_scripts_data;
@ -1175,6 +1187,7 @@ typedef struct mdb_cc_place_data_t
uint32_t priority;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(namer)
VARINT_FIELD(height)
FIELD(x0)
@ -1206,6 +1219,7 @@ typedef struct mdb_cc_user_texture_data_t
uint32_t vscale;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(tx_id)
FIELD(nonce)
FIELD(block)
@ -1229,6 +1243,7 @@ typedef struct mdb_cc_merchant_ship_available_items_t
bool recurring;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(item)
VARINT_FIELD(amount)
VARINT_FIELD(price)
@ -1240,6 +1255,7 @@ typedef struct mdb_cc_merchant_ship_available_items_t
std::vector<item_t> items;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(items)
END_SERIALIZE()
} mdb_cc_merchant_ship_available_items_t;
@ -1256,6 +1272,7 @@ typedef struct mdb_cc_merchant_ship_data_t
std::vector<uint64_t> nonces;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(height)
TEXT_FIELD(ship_name)
TEXT_FIELD(origin)
@ -1272,6 +1289,7 @@ typedef struct mdb_cc_epoch_t
std::string name;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
TEXT_FIELD(name)
END_SERIALIZE()
} mdb_cc_epoch_t;
@ -6066,10 +6084,10 @@ bool BlockchainLMDB::get_cc_account_balance(uint32_t id, uint64_t &balance) cons
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve account data: ", result).c_str()));
// this relies on balance being a 64 bit field right after three public keys
if (v.mv_size < 32 * 3 + 8)
if (v.mv_size < 32 * 3 + 8 + 1)
throw0(DB_ERROR("Account data too small"));
balance = *(uint64_t*)(((uint8_t*)v.mv_data) + 32 * 3);
balance = *(uint64_t*)(((uint8_t*)v.mv_data) + 32 * 3 + 1);
TXN_POSTFIX_RDONLY();
return true;
@ -6091,12 +6109,12 @@ void BlockchainLMDB::set_cc_account_balance(uint32_t id, uint64_t balance)
throw0(DB_ERROR(lmdb_error("Account " + std::to_string(id) + " not found: ", result).c_str()));
// this relies on balance being a 64 bit field right after three public keys
if (v.mv_size < 32 * 3 + 8)
if (v.mv_size < 32 * 3 + 8 + 1)
throw0(DB_ERROR("Account data too small"));
std::unique_ptr<uint8_t[]> vcopy(new uint8_t[v.mv_size]);
memcpy(vcopy.get(), v.mv_data, v.mv_size);
*(uint64_t*)(((uint8_t*)vcopy.get()) + 32 * 3) = balance;
*(uint64_t*)(((uint8_t*)vcopy.get()) + 32 * 3 + 1) = balance;
v.mv_data = vcopy.get();
result = mdb_cursor_put(m_cur_cc_accounts, &k, &v, 0);
@ -6123,12 +6141,12 @@ bool BlockchainLMDB::change_cc_account_balance(uint32_t id, int64_t delta_balanc
throw0(DB_ERROR(lmdb_error("Account " + std::to_string(id) + " not found: ", result).c_str()));
// this relies on balance being a 64 bit field right after three public keys
if (v.mv_size < 32 * 3 + 8)
if (v.mv_size < 32 * 3 + 8 + 1)
throw0(DB_ERROR("Account data too small"));
std::unique_ptr<uint8_t[]> vcopy(new uint8_t[v.mv_size]);
memcpy(vcopy.get(), v.mv_data, v.mv_size);
uint64_t &balance = *(uint64_t*)(((uint8_t*)vcopy.get()) + 32 * 3);
uint64_t &balance = *(uint64_t*)(((uint8_t*)vcopy.get()) + 32 * 3 + 1);
if (delta_balance > 0)
{
@ -7060,10 +7078,10 @@ bool BlockchainLMDB::get_cc_city_treasury(uint32_t id, uint32_t &treasury) const
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve city data: ", result).c_str()));
// this relies on treasury being a 32 bit field right after another 32 bit field
if (v.mv_size < 4 + 4)
if (v.mv_size < 4 + 4 + 1)
throw0(DB_ERROR("City data too small"));
treasury = *(uint32_t*)(((uint8_t*)v.mv_data) + 4);
treasury = *(uint32_t*)(((uint8_t*)v.mv_data) + 4 + 1);
TXN_POSTFIX_RDONLY();
return true;