diff --git a/common/db/src/db_macro.rs b/common/db/src/db_macro.rs index 644d874d7..c2fc3a0a5 100644 --- a/common/db/src/db_macro.rs +++ b/common/db/src/db_macro.rs @@ -1,34 +1,33 @@ #[macro_export] macro_rules! createDb { - ($db_name: ident - { $($field_name: ident: $field_type: ty),*} - ) => { - fn db_key(db_dst: &'static [u8], item_dst: &'static [u8], key: impl AsRef<[u8]>) -> Vec { - let db_len = u8::try_from(db_dst.len()).unwrap(); - let dst_len = u8::try_from(item_dst.len()).unwrap(); - [[db_len].as_ref(), db_dst, [dst_len].as_ref(), item_dst, key.as_ref()].concat() - } - - $( - #[derive(Clone, Debug)] - pub struct $field_name; - impl $field_name { + ($db_name: ident + { $($field_name: ident: $field_type: ty),*} + ) => { + fn db_key(db_dst: &'static [u8], item_dst: &'static [u8], key: impl AsRef<[u8]>) -> Vec { + let db_len = u8::try_from(db_dst.len()).unwrap(); + let dst_len = u8::try_from(item_dst.len()).unwrap(); + [[db_len].as_ref(), db_dst, [dst_len].as_ref(), item_dst, key.as_ref()].concat() + } - pub fn key(key: impl AsRef<[u8]>) -> Vec { - db_key(stringify!($db_name).as_bytes(), stringify!($field_name).as_bytes(), key) - } - #[allow(dead_code)] - pub fn set(txn: &mut impl DbTxn, key: impl AsRef<[u8]>, data: &impl serde::Serialize) { - let key = $field_name::key(key); - txn.put(&key, bincode::serialize(data).unwrap()); - } - #[allow(dead_code)] - pub fn get(getter: &impl Get, key: impl AsRef<[u8]>) -> Option<$field_type> { - getter.get($field_name::key(key)).map(|data| { - bincode::deserialize(data.as_ref()).unwrap() - }) - } - } - )* - }; - } + $( + #[derive(Clone, Debug)] + pub struct $field_name; + impl $field_name { + pub fn key(key: impl AsRef<[u8]>) -> Vec { + db_key(stringify!($db_name).as_bytes(), stringify!($field_name).as_bytes(), key) + } + #[allow(dead_code)] + pub fn set(txn: &mut impl DbTxn, key: impl AsRef<[u8]>, data: &impl serde::Serialize) { + let key = $field_name::key(key); + txn.put(&key, bincode::serialize(data).unwrap()); + } + #[allow(dead_code)] + pub fn get(getter: &impl Get, key: impl AsRef<[u8]>) -> Option<$field_type> { + getter.get($field_name::key(key)).map(|data| { + bincode::deserialize(data.as_ref()).unwrap() + }) + } + } + )* + }; +} diff --git a/processor/src/key_gen.rs b/processor/src/key_gen.rs index 076337972..9c2ba8abd 100644 --- a/processor/src/key_gen.rs +++ b/processor/src/key_gen.rs @@ -33,7 +33,7 @@ createDb!( CommitmentsDb: HashMap>, GeneratedKeysDb: Vec, KeysDb: Vec -} + } ); #[allow(clippy::type_complexity)]