mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
contract/dao: Avoid unnecessary db key serialization
This commit is contained in:
@@ -83,7 +83,7 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
||||
};
|
||||
|
||||
// Set up the entries in the header table
|
||||
match db_get(dao_info_db, &serialize(&DAO_CONTRACT_KEY_DAO_MERKLE_TREE))? {
|
||||
match db_get(dao_info_db, DAO_CONTRACT_KEY_DAO_MERKLE_TREE)? {
|
||||
Some(bytes) => {
|
||||
// We found some bytes, try to deserialize into a tree.
|
||||
// For now, if this doesn't work, we bail.
|
||||
@@ -99,7 +99,7 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
||||
tree_data.write_u32(0)?;
|
||||
tree.encode(&mut tree_data)?;
|
||||
|
||||
db_set(dao_info_db, &serialize(&DAO_CONTRACT_KEY_DAO_MERKLE_TREE), &tree_data)?;
|
||||
db_set(dao_info_db, DAO_CONTRACT_KEY_DAO_MERKLE_TREE, &tree_data)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,11 +130,7 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
|
||||
};
|
||||
|
||||
// Update db version
|
||||
db_set(
|
||||
dao_info_db,
|
||||
&serialize(&DAO_CONTRACT_KEY_DB_VERSION),
|
||||
&serialize(&env!("CARGO_PKG_VERSION")),
|
||||
)?;
|
||||
db_set(dao_info_db, DAO_CONTRACT_KEY_DB_VERSION, &serialize(&env!("CARGO_PKG_VERSION")))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ pub(crate) fn dao_mint_process_update(cid: ContractId, update: DaoMintUpdate) ->
|
||||
merkle_add(
|
||||
info_db,
|
||||
roots_db,
|
||||
&serialize(&DAO_CONTRACT_KEY_LATEST_DAO_ROOT),
|
||||
&serialize(&DAO_CONTRACT_KEY_DAO_MERKLE_TREE),
|
||||
DAO_CONTRACT_KEY_LATEST_DAO_ROOT,
|
||||
DAO_CONTRACT_KEY_DAO_MERKLE_TREE,
|
||||
&dao,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ pub(crate) fn dao_propose_process_instruction(
|
||||
|
||||
// Snapshot the latest Money Mekrle tree
|
||||
let money_info_db = db_lookup(*MONEY_CONTRACT_ID, MONEY_CONTRACT_INFO_TREE)?;
|
||||
let Some(data) = db_get(money_info_db, &serialize(&MONEY_CONTRACT_LATEST_COIN_ROOT))? else {
|
||||
let Some(data) = db_get(money_info_db, MONEY_CONTRACT_LATEST_COIN_ROOT)? else {
|
||||
msg!("[Dao::Propose] Error: Failed to fetch latest Money Merkle root");
|
||||
return Err(ContractError::Internal)
|
||||
};
|
||||
|
||||
@@ -66,9 +66,9 @@ pub const DAO_CONTRACT_DB_PROPOSAL_BULLAS: &str = "dao_proposals";
|
||||
pub const DAO_CONTRACT_DB_VOTE_NULLIFIERS: &str = "dao_vote_nullifiers";
|
||||
|
||||
// These are keys inside the info tree
|
||||
pub const DAO_CONTRACT_KEY_DB_VERSION: &str = "db_version";
|
||||
pub const DAO_CONTRACT_KEY_DAO_MERKLE_TREE: &str = "dao_merkle_tree";
|
||||
pub const DAO_CONTRACT_KEY_LATEST_DAO_ROOT: &str = "dao_last_root";
|
||||
pub const DAO_CONTRACT_KEY_DB_VERSION: &[u8] = b"db_version";
|
||||
pub const DAO_CONTRACT_KEY_DAO_MERKLE_TREE: &[u8] = b"dao_merkle_tree";
|
||||
pub const DAO_CONTRACT_KEY_LATEST_DAO_ROOT: &[u8] = b"dao_last_root";
|
||||
|
||||
/// zkas dao mint circuit namespace
|
||||
pub const DAO_CONTRACT_ZKAS_DAO_MINT_NS: &str = "DaoMint";
|
||||
|
||||
Reference in New Issue
Block a user