Skip to content

Commit

Permalink
wip: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjohnbell committed Nov 3, 2023
1 parent cba4c4b commit fbc7d3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
26 changes: 15 additions & 11 deletions common/db/src/create_db.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
pub fn db_key(db_dst: &'static [u8], item_dst: &'static [u8], key: impl AsRef<[u8]>) -> Vec<u8> {
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()
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()
}

/// Creates a series of structs which provide namespacing for keys
///
///
/// # Description
///
///
/// Creates a unit struct and a default implementation for the `key`, `get`, and `set`. The macro
/// uses a syntax similar to defining a function. Parameters are concatenated to produce a key,
/// they must be `scale` encodable. The return type is used to auto encode and decode the database
/// value bytes using `bincode`.
///
///
/// # Arguments
///
///
/// * `db_name` - A database name
/// * `field_name` - An item name
/// * `args` - Comma seperated list of key arguments
/// * `field_type` - The return type
///
///
/// # Example
///
///
/// ```
/// create_db!({
/// TrubutariesDb {
/// AttemptsDb: (key_bytes: &[u8], attempt_id: u32) -> u64,
/// AttemptsDb: (key_bytes: &[u8], attempt_id: u32) -> u64,
/// ExpiredDb: (genesis: [u8; 32]) -> Vec<u8>
/// }
/// })
Expand All @@ -40,7 +40,11 @@ macro_rules! create_db {
pub struct $field_name;
impl $field_name {
pub fn key($($arg: $arg_type),*) -> Vec<u8> {
$crate::db_key(stringify!($db_name).as_bytes(), stringify!($field_name).as_bytes(), (vec![] as Vec<u8>, $($arg),*).encode())
$crate::db_key(
stringify!($db_name).as_bytes(),
stringify!($field_name).as_bytes(),
(vec![] as Vec<u8>, $($arg),*).encode()
)
}
#[allow(dead_code)]
pub fn set(txn: &mut impl DbTxn $(, $arg: $arg_type)*, data: &impl serde::Serialize) {
Expand Down
13 changes: 10 additions & 3 deletions processor/src/key_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl KeysDb {
N::tweak_keys(&mut network_keys);
Some((keys_vec, (substrate_keys, network_keys)))
}

fn confirm_keys<N: Network>(
txn: &mut impl DbTxn,
set: ValidatorSet,
Expand All @@ -69,7 +69,7 @@ impl KeysDb {
txn.put(KeysDb::key(&keys.1.group_key().to_bytes().as_ref().into()), keys_vec);
keys
}

fn keys<N: Network>(
getter: &impl Get,
key: &<N::Curve as Ciphersuite>::G,
Expand All @@ -88,7 +88,14 @@ impl GeneratedKeysDb {
) {
let mut keys = substrate_keys.serialize();
keys.extend(network_keys.serialize().iter());
txn.put(Self::key(&id.set, &substrate_keys.group_key().to_bytes(), network_keys.group_key().to_bytes().as_ref()), keys);
txn.put(
Self::key(
&id.set,
&substrate_keys.group_key().to_bytes(),
network_keys.group_key().to_bytes().as_ref(),
),
keys,
);
}
}

Expand Down

0 comments on commit fbc7d3e

Please sign in to comment.