Skip to content

Commit

Permalink
Merge pull request #41 from 5ire-tech/dami/fix-lint
Browse files Browse the repository at this point in the history
Fix Linting Issues
  • Loading branch information
dharjeezy authored Aug 9, 2023
2 parents a4ad758 + 3b20229 commit 55de99e
Show file tree
Hide file tree
Showing 78 changed files with 1,236 additions and 2,114 deletions.
65 changes: 20 additions & 45 deletions client/cli/src/frontier_db_cmd/mapping_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ where
C: sp_blockchain::HeaderBackend<B>,
{
pub fn new(cmd: &'a FrontierDbCmd, client: Arc<C>, backend: Arc<fc_db::Backend<B>>) -> Self {
Self {
cmd,
client,
backend,
}
Self { cmd, client, backend }
}

pub fn query(
Expand All @@ -70,24 +66,16 @@ where
(
MappingKey::EthBlockOrTransactionHash(ethereum_block_hash),
Some(MappingValue::SubstrateBlockHash(substrate_block_hash)),
) => {
if self
.backend
.mapping()
.block_hash(ethereum_block_hash)?
.is_none()
{
) =>
if self.backend.mapping().block_hash(ethereum_block_hash)?.is_none() {
let id = BlockId::Hash(*substrate_block_hash);
let existing_transaction_hashes: Vec<H256> = if let Some(statuses) = self
.client
.runtime_api()
.current_transaction_statuses(&id)
.map_err(|e| format!("{:?}", e))?
.map_err(|e| format!("{e:?}"))?
{
statuses
.iter()
.map(|t| t.transaction_hash)
.collect::<Vec<H256>>()
statuses.iter().map(|t| t.transaction_hash).collect::<Vec<H256>>()
} else {
vec![]
};
Expand All @@ -100,53 +88,42 @@ where

self.backend.mapping().write_hashes(commitment)?;
} else {
return Err(self.key_not_empty_error(key));
}
}
return Err(self.key_not_empty_error(key))
},
_ => return Err(self.key_value_error(key, value)),
},
Operation::Read => match (column, key) {
// Given ethereum block hash, get substrate block hash.
(Column::Block, MappingKey::EthBlockOrTransactionHash(ethereum_block_hash)) => {
let value = self.backend.mapping().block_hash(ethereum_block_hash)?;
println!("{:?}", value);
}
println!("{value:?}");
},
// Given ethereum transaction hash, get transaction metadata.
(
Column::Transaction,
MappingKey::EthBlockOrTransactionHash(ethereum_transaction_hash),
) => {
let value = self
.backend
.mapping()
.transaction_metadata(ethereum_transaction_hash)?;
println!("{:?}", value);
}
let value =
self.backend.mapping().transaction_metadata(ethereum_transaction_hash)?;
println!("{value:?}");
},
_ => return Err(self.key_column_error(key, value)),
},
Operation::Update => match (key, value) {
// Update a mapping commitment using the state at the requested block.
(
MappingKey::EthBlockOrTransactionHash(ethereum_block_hash),
Some(MappingValue::SubstrateBlockHash(substrate_block_hash)),
) => {
if self
.backend
.mapping()
.block_hash(ethereum_block_hash)?
.is_some()
{
) =>
if self.backend.mapping().block_hash(ethereum_block_hash)?.is_some() {
let id = BlockId::Hash(*substrate_block_hash);
let existing_transaction_hashes: Vec<H256> = if let Some(statuses) = self
.client
.runtime_api()
.current_transaction_statuses(&id)
.map_err(|e| format!("{:?}", e))?
.map_err(|e| format!("{e:?}"))?
{
statuses
.iter()
.map(|t| t.transaction_hash)
.collect::<Vec<H256>>()
statuses.iter().map(|t| t.transaction_hash).collect::<Vec<H256>>()
} else {
vec![]
};
Expand All @@ -158,15 +135,13 @@ where
};

self.backend.mapping().write_hashes(commitment)?;
}
}
},
_ => return Err(self.key_value_error(key, value)),
},
Operation::Delete => {
Operation::Delete =>
return Err("Delete operation is not supported for non-static keys"
.to_string()
.into())
}
.into()),
}
Ok(())
}
Expand Down
36 changes: 16 additions & 20 deletions client/cli/src/frontier_db_cmd/meta_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl FromStr for MetaKey {
match input {
x if x == tips => Ok(MetaKey::Tips),
y if y == schema => Ok(MetaKey::Schema),
_ => Err(format!("`{:?}` is not a meta column static key", input).into()),
_ => Err(format!("`{input:?}` is not a meta column static key").into()),
}
}
}
Expand All @@ -73,48 +73,44 @@ impl<'a, B: BlockT> MetaDb<'a, B> {
// Insert data to the meta column, static tips key.
(MetaKey::Tips, Some(MetaValue::Tips(hashes))) => {
if self.backend.meta().current_syncing_tips()?.is_empty() {
self.backend
.meta()
.write_current_syncing_tips(hashes.clone())?;
self.backend.meta().write_current_syncing_tips(hashes.clone())?;
} else {
return Err(self.key_not_empty_error(key));
return Err(self.key_not_empty_error(key))
}
}
},
// Insert data to the meta column, static schema cache key.
(MetaKey::Schema, Some(MetaValue::Schema(schema_map))) => {
if self.backend.meta().ethereum_schema()?.is_none() {
let data:Vec<(fp_storage::EthereumStorageSchema, H256)> = schema_map
let data: Vec<(fp_storage::EthereumStorageSchema, H256)> = schema_map
.iter()
.map(|(key, value)| (*value, *key))
.collect::<Vec<(fp_storage::EthereumStorageSchema, H256)>>();
self.backend.meta().write_ethereum_schema(data)?;
} else {
return Err(self.key_not_empty_error(key));
return Err(self.key_not_empty_error(key))
}
}
},
_ => return Err(self.key_value_error(key, value)),
},
Operation::Read => match key {
// Read meta column, static tips key.
MetaKey::Tips => {
let value = self.backend.meta().current_syncing_tips()?;
println!("{:?}", value);
}
println!("{value:?}");
},
// Read meta column, static schema cache key.
MetaKey::Schema => {
let value = self.backend.meta().ethereum_schema()?;
println!("{:?}", value);
}
println!("{value:?}");
},
},
Operation::Update => match (key, value) {
// Update the static tips key's value.
(MetaKey::Tips, Some(MetaValue::Tips(new_value))) => {
let value = self.backend.meta().current_syncing_tips()?;
self.confirmation_prompt(&self.cmd.operation, key, &value, new_value)?;
self.backend
.meta()
.write_current_syncing_tips(new_value.clone())?;
}
self.backend.meta().write_current_syncing_tips(new_value.clone())?;
},
// Update the static schema cache key's value.
(MetaKey::Schema, Some(MetaValue::Schema(schema_map))) => {
let value = self.backend.meta().ethereum_schema()?;
Expand All @@ -129,7 +125,7 @@ impl<'a, B: BlockT> MetaDb<'a, B> {
&Some(new_value.clone()),
)?;
self.backend.meta().write_ethereum_schema(new_value)?;
}
},
_ => return Err(self.key_value_error(key, value)),
},
Operation::Delete => match key {
Expand All @@ -138,13 +134,13 @@ impl<'a, B: BlockT> MetaDb<'a, B> {
let value = self.backend.meta().current_syncing_tips()?;
self.confirmation_prompt(&self.cmd.operation, key, &value, &vec![])?;
self.backend.meta().write_current_syncing_tips(vec![])?;
}
},
// Deletes the static schema cache key's value.
MetaKey::Schema => {
let value = self.backend.meta().ethereum_schema()?;
self.confirmation_prompt(&self.cmd.operation, key, &value, &Some(vec![]))?;
self.backend.meta().write_ethereum_schema(vec![])?;
}
},
},
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/frontier_db_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl FrontierDbCmd {
};
// Run the query
meta_db.query(&key, &value)?
}
},
Column::Block | Column::Transaction => {
// New mapping db handler
let mapping_db = MappingDb::new(self, client, backend);
Expand All @@ -142,7 +142,7 @@ impl FrontierDbCmd {
};
// Run the query
mapping_db.query(&self.column, &key, &value)?
}
},
}
Ok(())
}
Expand Down
Loading

0 comments on commit 55de99e

Please sign in to comment.