From d008ca8a0b22bce79716260606f6c2c2e5e09b71 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Mon, 27 Nov 2023 12:59:07 +0300 Subject: [PATCH] Fixed clippy warning in VDR library Signed-off-by: artem.ivanov --- indy-besu/vdr/src/client/client.rs | 56 ++++----- .../src/client/implementation/web3/client.rs | 20 ++-- .../src/client/implementation/web3/signer.rs | 16 +-- indy-besu/vdr/src/client/types/contract.rs | 110 ++++++++---------- indy-besu/vdr/src/contracts/auth/role.rs | 20 ++-- .../vdr/src/contracts/auth/role_control.rs | 20 ++-- .../cl/credential_definition_registry.rs | 6 +- .../vdr/src/contracts/cl/schema_registry.rs | 6 +- .../cl/types/credential_definition.rs | 32 ++--- .../vdr/src/contracts/cl/types/schema.rs | 33 +++--- .../vdr/src/contracts/did/did_registry.rs | 10 +- .../vdr/src/contracts/did/types/did_doc.rs | 108 +++++++++-------- .../contracts/network/validator_control.rs | 8 +- indy-besu/vdr/src/lib.rs | 1 + indy-besu/vdr/src/signer/basic_signer.rs | 4 +- 15 files changed, 226 insertions(+), 224 deletions(-) diff --git a/indy-besu/vdr/src/client/client.rs b/indy-besu/vdr/src/client/client.rs index 099c6ddbf..74aeef511 100644 --- a/indy-besu/vdr/src/client/client.rs +++ b/indy-besu/vdr/src/client/client.rs @@ -31,7 +31,7 @@ impl LedgerClient { pub fn new( chain_id: u64, node_address: &str, - contract_configs: &Vec, + contract_configs: &[ContractConfig], // TODO: It is simplier to just pass signer only into corresponding `sign_transaction` function. // But we also have single step functions like `create_did` where we will have to pass call back as well // Transaction methods already depends on the client, so it make sence to accept signer on client create @@ -45,7 +45,7 @@ impl LedgerClient { ); let client = Web3Client::new(node_address, signer)?; - let contracts = Self::init_contracts(&client, &contract_configs)?; + let contracts = Self::init_contracts(&client, contract_configs)?; let ledger_client = LedgerClient { chain_id, @@ -77,7 +77,7 @@ impl LedgerClient { /// # Returns /// signed transaction to submit pub async fn sign_transaction(&self, transaction: &Transaction) -> VdrResult { - self.client.sign_transaction(&transaction).await + self.client.sign_transaction(transaction).await } /// Submit prepared transaction to the ledger @@ -91,8 +91,8 @@ impl LedgerClient { /// depending on the type it will be either result bytes or block hash pub async fn submit_transaction(&self, transaction: &Transaction) -> VdrResult> { match transaction.type_ { - TransactionType::Read => self.client.call_transaction(&transaction).await, - TransactionType::Write => self.client.submit_transaction(&transaction).await, + TransactionType::Read => self.client.call_transaction(transaction).await, + TransactionType::Write => self.client.submit_transaction(transaction).await, } } @@ -108,19 +108,22 @@ impl LedgerClient { } pub(crate) async fn sign_and_submit(&self, transaction: &Transaction) -> VdrResult { - let signed_transaction = self.sign_transaction(&transaction).await?; + let signed_transaction = self.sign_transaction(transaction).await?; let block_hash = self.submit_transaction(&signed_transaction).await?; self.get_receipt(&block_hash).await } - pub(crate) fn contract(&self, name: &str) -> VdrResult<&Box> { - self.contracts.get(name).ok_or_else(|| { - let vdr_error = VdrError::ContractInvalidName(name.to_string()); + pub(crate) fn contract(&self, name: &str) -> VdrResult<&dyn Contract> { + self.contracts + .get(name) + .map(|contract| contract.as_ref()) + .ok_or_else(|| { + let vdr_error = VdrError::ContractInvalidName(name.to_string()); - warn!("Error during getting contract: {:?}", vdr_error); + warn!("Error during getting contract: {:?}", vdr_error); - vdr_error - }) + vdr_error + }) } pub(crate) fn chain_id(&self) -> u64 { @@ -149,22 +152,19 @@ pub mod test { use std::{env, fs}; pub const CHAIN_ID: u64 = 1337; - pub const NODE_ADDRESS: &'static str = "http://127.0.0.1:8545"; - pub const CONTRACTS_SPEC_BASE_PATH: &'static str = "../smart_contracts/artifacts/contracts/"; - pub const DID_REGISTRY_ADDRESS: &'static str = "0x0000000000000000000000000000000000003333"; - pub const DID_REGISTRY_SPEC_PATH: &'static str = "did/DidRegistry.sol/DidRegistry.json"; - pub const SCHEMA_REGISTRY_ADDRESS: &'static str = "0x0000000000000000000000000000000000005555"; - pub const SCHEMA_REGISTRY_SPEC_PATH: &'static str = "cl/SchemaRegistry.sol/SchemaRegistry.json"; - pub const CRED_DEF_REGISTRY_ADDRESS: &'static str = - "0x0000000000000000000000000000000000004444"; - pub const CRED_DEF_REGISTRY_SPEC_PATH: &'static str = + pub const NODE_ADDRESS: &str = "http://127.0.0.1:8545"; + pub const CONTRACTS_SPEC_BASE_PATH: &str = "../smart_contracts/artifacts/contracts/"; + pub const DID_REGISTRY_ADDRESS: &str = "0x0000000000000000000000000000000000003333"; + pub const DID_REGISTRY_SPEC_PATH: &str = "did/DidRegistry.sol/DidRegistry.json"; + pub const SCHEMA_REGISTRY_ADDRESS: &str = "0x0000000000000000000000000000000000005555"; + pub const SCHEMA_REGISTRY_SPEC_PATH: &str = "cl/SchemaRegistry.sol/SchemaRegistry.json"; + pub const CRED_DEF_REGISTRY_ADDRESS: &str = "0x0000000000000000000000000000000000004444"; + pub const CRED_DEF_REGISTRY_SPEC_PATH: &str = "cl/CredentialDefinitionRegistry.sol/CredentialDefinitionRegistry.json"; - pub const VALIDATOR_CONTROL_ADDRESS: &'static str = - "0x0000000000000000000000000000000000007777"; - pub const VALIDATOR_CONTROL_PATH: &'static str = - "network/ValidatorControl.sol/ValidatorControl.json"; - pub const ROLE_CONTROL_ADDRESS: &'static str = "0x0000000000000000000000000000000000006666"; - pub const ROLE_CONTROL_PATH: &'static str = "auth/RoleControl.sol/RoleControl.json"; + pub const VALIDATOR_CONTROL_ADDRESS: &str = "0x0000000000000000000000000000000000007777"; + pub const VALIDATOR_CONTROL_PATH: &str = "network/ValidatorControl.sol/ValidatorControl.json"; + pub const ROLE_CONTROL_ADDRESS: &str = "0x0000000000000000000000000000000000006666"; + pub const ROLE_CONTROL_PATH: &str = "auth/RoleControl.sol/RoleControl.json"; fn build_contract_path(contract_path: &str) -> String { let mut cur_dir = env::current_dir().unwrap(); @@ -203,7 +203,7 @@ pub mod test { } pub fn client(signer: Option) -> LedgerClient { - let signer = signer.unwrap_or_else(|| basic_signer()); + let signer = signer.unwrap_or_else(basic_signer); LedgerClient::new(CHAIN_ID, NODE_ADDRESS, &contracts(), Some(Box::new(signer))).unwrap() } diff --git a/indy-besu/vdr/src/client/implementation/web3/client.rs b/indy-besu/vdr/src/client/implementation/web3/client.rs index 2338e66ac..e1103b863 100644 --- a/indy-besu/vdr/src/client/implementation/web3/client.rs +++ b/indy-besu/vdr/src/client/implementation/web3/client.rs @@ -55,16 +55,20 @@ impl Client for Web3Client { transaction ); - let signer = self.signer.as_ref().ok_or_else(|| { - let vdr_error = VdrError::ClientInvalidState("Signer is not set".to_string()); + let signer = self + .signer + .as_ref() + .ok_or_else(|| { + let vdr_error = VdrError::ClientInvalidState("Signer is not set".to_string()); - warn!( - "Error: {} during signing transaction: {:?}", - vdr_error, transaction - ); + warn!( + "Error: {} during signing transaction: {:?}", + vdr_error, transaction + ); - vdr_error - })?; + vdr_error + })? + .as_ref(); let account = transaction.from.clone().ok_or_else(|| { let vdr_error = VdrError::ClientInvalidTransaction("Missing sender address".to_string()); diff --git a/indy-besu/vdr/src/client/implementation/web3/signer.rs b/indy-besu/vdr/src/client/implementation/web3/signer.rs index f9945ee6d..7493de09a 100644 --- a/indy-besu/vdr/src/client/implementation/web3/signer.rs +++ b/indy-besu/vdr/src/client/implementation/web3/signer.rs @@ -13,11 +13,11 @@ use web3::{ /// Rust Web3 crate does not expose `encode` functions, instead we have to implement the interface bellow pub struct Web3Signer<'a> { account: Address, - signer: &'a Box, + signer: &'a dyn Signer, } impl<'a> Web3Signer<'a> { - pub fn new(account: Address, signer: &'a Box) -> Web3Signer<'a> { + pub fn new(account: Address, signer: &'a dyn Signer) -> Web3Signer<'a> { let signer = Web3Signer { account: account.clone(), signer, @@ -34,7 +34,7 @@ impl<'a> Key for Web3Signer<'a> { fn sign(&self, message: &[u8], chain_id: Option) -> Result { let signature_data = self .signer - .sign(message, &self.account.value()) + .sign(message, self.account.value()) .map_err(|_| { let web3_err = SigningError::InvalidMessage; @@ -44,8 +44,8 @@ impl<'a> Key for Web3Signer<'a> { })?; let v = match chain_id { - Some(chain_id) => signature_data.recovery_id as u64 + 35 + chain_id * 2, - None => signature_data.recovery_id as u64 + 27, + Some(chain_id) => signature_data.recovery_id + 35 + chain_id * 2, + None => signature_data.recovery_id + 27, }; let signature = Signature { @@ -62,11 +62,11 @@ impl<'a> Key for Web3Signer<'a> { fn sign_message(&self, message: &[u8]) -> Result { let signature_data = self .signer - .sign(message, &self.account.value()) + .sign(message, self.account.value()) .map_err(|_| SigningError::InvalidMessage)?; let signature = Signature { - v: signature_data.recovery_id as u64, + v: signature_data.recovery_id, r: H256::from_slice(&signature_data.signature[..32]), s: H256::from_slice(&signature_data.signature[32..]), }; @@ -77,6 +77,6 @@ impl<'a> Key for Web3Signer<'a> { } fn address(&self) -> EtabiAddress { - EtabiAddress::from_str(&self.account.value()).unwrap_or_default() + EtabiAddress::from_str(self.account.value()).unwrap_or_default() } } diff --git a/indy-besu/vdr/src/client/types/contract.rs b/indy-besu/vdr/src/client/types/contract.rs index 003578ade..646129551 100644 --- a/indy-besu/vdr/src/client/types/contract.rs +++ b/indy-besu/vdr/src/client/types/contract.rs @@ -90,37 +90,35 @@ impl ContractOutput { pub fn get_tuple(&self, index: usize) -> VdrResult { self.0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing tuple value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing tuple value".to_string()) + })? .clone() .into_tuple() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing tuple value".to_string(), - )) - .map(|result| ContractOutput(result)) + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing tuple value".to_string())) + .map(ContractOutput) } pub fn get_string(&self, index: usize) -> VdrResult { self.0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing string value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing string value".to_string()) + })? .clone() .into_string() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing string value".to_string(), - )) + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing string value".to_string()) + }) } pub fn get_address(&self, index: usize) -> VdrResult
{ let address_str = self .0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing address value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing address value".to_string()) + })? .clone() .to_string(); @@ -130,28 +128,20 @@ impl ContractOutput { pub fn get_bool(&self, index: usize) -> VdrResult { self.0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing bool value".to_string(), - ))? + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing bool value".to_string()))? .clone() .into_bool() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing bool value".to_string(), - )) + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing bool value".to_string())) } pub fn get_u128(&self, index: usize) -> VdrResult { Ok(self .0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing uint value".to_string(), - ))? + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing uint value".to_string()))? .clone() .into_uint() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing uint value".to_string(), - ))? + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing uint value".to_string()))? .as_u128()) } @@ -159,35 +149,29 @@ impl ContractOutput { Ok(self .0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing uint value".to_string(), - ))? + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing uint value".to_string()))? .clone() .into_uint() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing uint value".to_string(), - ))? + .ok_or_else(|| VdrError::ContractInvalidResponseData("Missing uint value".to_string()))? .as_u32() as u8) } pub fn get_string_array(&self, index: usize) -> VdrResult> { self.0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing string array value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing string array value".to_string()) + })? .clone() .into_array() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing string array value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing string array value".to_string()) + })? .into_iter() .map(|token| { - token - .into_string() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing string value".to_string(), - )) + token.into_string().ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing string value".to_string()) + }) }) .collect() } @@ -196,14 +180,18 @@ impl ContractOutput { Ok(self .0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing address string array value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData( + "Missing address string array value".to_string(), + ) + })? .clone() .into_array() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing address string array value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData( + "Missing address string array value".to_string(), + ) + })? .into_iter() .map(|token| Address::new(&token.to_string())) .collect()) @@ -213,22 +201,20 @@ impl ContractOutput { let tokens = self .0 .get(index) - .ok_or(VdrError::ContractInvalidResponseData( - "Missing object array value".to_string(), - ))? + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing object array value".to_string()) + })? .clone() .into_array() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing object array value".to_string(), - ))?; + .ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing object array value".to_string()) + })?; let mut result: Vec = Vec::new(); for item in tokens.into_iter() { - let item = item - .into_tuple() - .ok_or(VdrError::ContractInvalidResponseData( - "Missing object value".to_string(), - ))?; + let item = item.into_tuple().ok_or_else(|| { + VdrError::ContractInvalidResponseData("Missing object value".to_string()) + })?; result.push(ContractOutput(item)) } Ok(result) diff --git a/indy-besu/vdr/src/contracts/auth/role.rs b/indy-besu/vdr/src/contracts/auth/role.rs index 8a950661f..d8621290c 100644 --- a/indy-besu/vdr/src/contracts/auth/role.rs +++ b/indy-besu/vdr/src/contracts/auth/role.rs @@ -17,16 +17,16 @@ pub enum Role { pub type HasRole = bool; pub type RoleIndex = u8; -impl Into for Role { - fn into(self) -> ContractParam { - trace!("Role: {:?} convert into ContractParam has started", self); +impl From for ContractParam { + fn from(value: Role) -> Self { + trace!("Role: {:?} convert into ContractParam has started", value); - let role_index: RoleIndex = self.into(); + let role_index: RoleIndex = value.into(); let role_contract_param = ContractParam::Uint(role_index.into()); trace!( "Role: {:?} convert into ContractParam has finished. Result: {:?}", - self, + value, role_contract_param ); @@ -53,15 +53,15 @@ impl TryFrom for Role { } } -impl Into for Role { - fn into(self) -> RoleIndex { - trace!("Role: {:?} convert into RoleIndex has started", self); +impl From for RoleIndex { + fn from(value: Role) -> Self { + trace!("Role: {:?} convert into RoleIndex has started", value); - let role_index = self as u8; + let role_index = value as u8; trace!( "Role: {:?} convert into RoleIndex has finished. Result: {}", - self, + value, role_index ); diff --git a/indy-besu/vdr/src/contracts/auth/role_control.rs b/indy-besu/vdr/src/contracts/auth/role_control.rs index 12ca44068..08ea1ded0 100644 --- a/indy-besu/vdr/src/contracts/auth/role_control.rs +++ b/indy-besu/vdr/src/contracts/auth/role_control.rs @@ -44,11 +44,11 @@ impl RoleControl { let transaction = TransactionBuilder::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_ASSIGN_ROLE) - .add_param(role.clone().into()) + .add_param((*role).into()) .add_param(account.clone().try_into()?) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -86,11 +86,11 @@ impl RoleControl { let transaction = TransactionBuilder::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_REVOKE_ROLE) - .add_param(role.clone().into()) + .add_param((*role).into()) .add_param(account.clone().try_into()?) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -125,10 +125,10 @@ impl RoleControl { let transaction = TransactionBuilder::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_HAS_ROLE) - .add_param(role.clone().into()) + .add_param((*role).into()) .add_param(account.clone().try_into()?) .set_type(TransactionType::Read) - .build(&client); + .build(client); info!( "{} txn build has finished. Result {:?}", @@ -162,7 +162,7 @@ impl RoleControl { .set_method(Self::METHOD_GET_ROLE) .add_param(account.clone().try_into()?) .set_type(TransactionType::Read) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -191,7 +191,7 @@ impl RoleControl { let parse_result = TransactionParser::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_HAS_ROLE) - .parse::(&client, bytes); + .parse::(client, bytes); info!( "{} result parse has finished. Result: {:?}", @@ -220,7 +220,7 @@ impl RoleControl { let parse_result = TransactionParser::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_GET_ROLE) - .parse::(&client, bytes); + .parse::(client, bytes); info!( "{} result parse has finished. Result: {:?}", @@ -375,7 +375,7 @@ pub mod test { utils::init_env_logger, }; - pub const NEW_ACCOUNT: &'static str = "0x0886328869e4e1f401e1052a5f4aae8b45f42610"; + pub const NEW_ACCOUNT: &str = "0x0886328869e4e1f401e1052a5f4aae8b45f42610"; fn account() -> Address { Address::new(NEW_ACCOUNT) diff --git a/indy-besu/vdr/src/contracts/cl/credential_definition_registry.rs b/indy-besu/vdr/src/contracts/cl/credential_definition_registry.rs index e2485e771..baa9fce91 100644 --- a/indy-besu/vdr/src/contracts/cl/credential_definition_registry.rs +++ b/indy-besu/vdr/src/contracts/cl/credential_definition_registry.rs @@ -48,7 +48,7 @@ impl CredentialDefinitionRegistry { .add_param(credential_definition.clone().into()) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -83,7 +83,7 @@ impl CredentialDefinitionRegistry { .set_method(Self::METHOD_RESOLVE_CREDENTIAL_DEFINITION) .add_param(ContractParam::String(id.value().into())) .set_type(TransactionType::Read) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -116,7 +116,7 @@ impl CredentialDefinitionRegistry { let result = TransactionParser::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_RESOLVE_CREDENTIAL_DEFINITION) - .parse::(&client, bytes) + .parse::(client, bytes) .map(|credential_definition_with_meta| { credential_definition_with_meta.credential_definition }); diff --git a/indy-besu/vdr/src/contracts/cl/schema_registry.rs b/indy-besu/vdr/src/contracts/cl/schema_registry.rs index 96dd3a57f..f74c08128 100644 --- a/indy-besu/vdr/src/contracts/cl/schema_registry.rs +++ b/indy-besu/vdr/src/contracts/cl/schema_registry.rs @@ -47,7 +47,7 @@ impl SchemaRegistry { .add_param(schema.clone().into()) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -81,7 +81,7 @@ impl SchemaRegistry { .set_method(Self::METHOD_RESOLVE_SCHEMA) .add_param(ContractParam::String(id.value().into())) .set_type(TransactionType::Read) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -110,7 +110,7 @@ impl SchemaRegistry { let result = TransactionParser::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_RESOLVE_SCHEMA) - .parse::(&client, bytes) + .parse::(client, bytes) .map(|schema_with_meta| schema_with_meta.schema); info!( diff --git a/indy-besu/vdr/src/contracts/cl/types/credential_definition.rs b/indy-besu/vdr/src/contracts/cl/types/credential_definition.rs index 525ee59af..57190412a 100644 --- a/indy-besu/vdr/src/contracts/cl/types/credential_definition.rs +++ b/indy-besu/vdr/src/contracts/cl/types/credential_definition.rs @@ -36,25 +36,25 @@ pub struct CredentialDefinitionMetadata { pub created: u128, } -impl Into for CredentialDefinition { - fn into(self) -> ContractParam { +impl From for ContractParam { + fn from(value: CredentialDefinition) -> Self { trace!( "CredentialDefinition: {:?} convert into ContractParam has started", - self + value ); let cred_def_contract_param = ContractParam::Tuple(vec![ - ContractParam::String(self.id.value().to_string()), - ContractParam::String(self.issuer_id.value().to_string()), - ContractParam::String(self.schema_id.value().to_string()), - ContractParam::String(self.cred_def_type.to_string()), - ContractParam::String(self.tag.to_string()), - ContractParam::String(self.value.to_string()), + ContractParam::String(value.id.value().to_string()), + ContractParam::String(value.issuer_id.value().to_string()), + ContractParam::String(value.schema_id.value().to_string()), + ContractParam::String(value.cred_def_type.to_string()), + ContractParam::String(value.tag.to_string()), + ContractParam::String(value.value.to_string()), ]); trace!( "CredentialDefinition: {:?} convert into ContractParam has finished. Result: {:?}", - self, + value, cred_def_contract_param ); @@ -161,9 +161,9 @@ pub mod test { }; use serde_json::json; - pub const _CREDENTIAL_DEFINITION_ID: &'static str = "did:indy2:testnet:3LpjszkgTmE3qThge25FZw/anoncreds/v0/CLAIM_DEF/did:indy2:testnet:3LpjszkgTmE3qThge25FZw/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0/default"; - pub const CREDENTIAL_DEFINITION_TAG: &'static str = "default"; - pub const CREDENTIAL_DEFINITION_TYPE: &'static str = "CL"; + pub const _CREDENTIAL_DEFINITION_ID: &str = "did:indy2:testnet:3LpjszkgTmE3qThge25FZw/anoncreds/v0/CLAIM_DEF/did:indy2:testnet:3LpjszkgTmE3qThge25FZw/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0/default"; + pub const CREDENTIAL_DEFINITION_TAG: &str = "default"; + pub const CREDENTIAL_DEFINITION_TYPE: &str = "CL"; pub fn credential_definition_id( issuer_id: &DID, @@ -188,11 +188,11 @@ pub mod test { schema_id: &SchemaId, tag: Option<&str>, ) -> CredentialDefinition { - let tag = tag.map(String::from).unwrap_or_else(|| rand_string()); + let tag = tag.map(String::from).unwrap_or_else(rand_string); CredentialDefinition { - id: credential_definition_id(&issuer_id, schema_id, tag.as_str()), + id: credential_definition_id(issuer_id, schema_id, tag.as_str()), issuer_id: issuer_id.clone(), - schema_id: SchemaId::new(&schema_id.value().to_string()), + schema_id: SchemaId::new(schema_id.value()), cred_def_type: CREDENTIAL_DEFINITION_TYPE.to_string(), tag: tag.to_string(), value: credential_definition_value(), diff --git a/indy-besu/vdr/src/contracts/cl/types/schema.rs b/indy-besu/vdr/src/contracts/cl/types/schema.rs index a6ae2c061..e9fa16b8f 100644 --- a/indy-besu/vdr/src/contracts/cl/types/schema.rs +++ b/indy-besu/vdr/src/contracts/cl/types/schema.rs @@ -30,17 +30,18 @@ pub struct SchemaMetadata { pub created: u128, } -impl Into for Schema { - fn into(self) -> ContractParam { - trace!("Schema: {:?} convert into ContractParam has started", self); +impl From for ContractParam { + fn from(value: Schema) -> Self { + trace!("Schema: {:?} convert into ContractParam has started", value); let schema_contract_param = ContractParam::Tuple(vec![ - ContractParam::String(self.id.value().to_string()), - ContractParam::String(self.issuer_id.value().to_string()), - ContractParam::String(self.name.to_string()), - ContractParam::String(self.version.to_string()), + ContractParam::String(value.id.value().to_string()), + ContractParam::String(value.issuer_id.value().to_string()), + ContractParam::String(value.name.to_string()), + ContractParam::String(value.version.to_string()), ContractParam::Array( - self.attr_names + value + .attr_names .iter() .map(|attr_name| ContractParam::String(attr_name.to_string())) .collect(), @@ -49,7 +50,7 @@ impl Into for Schema { trace!( "Schema: {:?} convert into ContractParam has finished. Result: {:?}", - self, + value, schema_contract_param ); @@ -139,21 +140,21 @@ pub mod test { use super::*; use crate::{contracts::did::types::did_doc::test::ISSUER_ID, utils::rand_string}; - pub const SCHEMA_ID: &'static str = + pub const SCHEMA_ID: &str = "did:indy2:testnet:3LpjszkgTmE3qThge25FZw/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0"; - pub const SCHEMA_NAME: &'static str = "F1DClaFEzi3t"; - pub const SCHEMA_VERSION: &'static str = "1.0.0"; - pub const SCHEMA_ATTRIBUTE_FIRST_NAME: &'static str = "First Name"; - pub const SCHEMA_ATTRIBUTE_LAST_NAME: &'static str = "Last Name"; + pub const SCHEMA_NAME: &str = "F1DClaFEzi3t"; + pub const SCHEMA_VERSION: &str = "1.0.0"; + pub const SCHEMA_ATTRIBUTE_FIRST_NAME: &str = "First Name"; + pub const SCHEMA_ATTRIBUTE_LAST_NAME: &str = "Last Name"; pub fn schema_id(issuer_id: &DID, name: &str) -> SchemaId { SchemaId::build(issuer_id, name, SCHEMA_VERSION) } pub fn schema(issuer_id: &DID, name: Option<&str>) -> Schema { - let name = name.map(String::from).unwrap_or_else(|| rand_string()); + let name = name.map(String::from).unwrap_or_else(rand_string); Schema { - id: schema_id(&issuer_id, name.as_str()), + id: schema_id(issuer_id, name.as_str()), issuer_id: issuer_id.clone(), name, version: SCHEMA_VERSION.to_string(), diff --git a/indy-besu/vdr/src/contracts/did/did_registry.rs b/indy-besu/vdr/src/contracts/did/did_registry.rs index e409fd099..716aa3f6f 100644 --- a/indy-besu/vdr/src/contracts/did/did_registry.rs +++ b/indy-besu/vdr/src/contracts/did/did_registry.rs @@ -47,7 +47,7 @@ impl DidRegistry { .add_param(did_doc.clone().into()) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -85,7 +85,7 @@ impl DidRegistry { .add_param(did_doc.clone().into()) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -123,7 +123,7 @@ impl DidRegistry { .add_param(ContractParam::String(did.value().to_string())) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -157,7 +157,7 @@ impl DidRegistry { .set_method(Self::METHOD_RESOLVE_DID) .add_param(ContractParam::String(did.value().to_string())) .set_type(TransactionType::Read) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -186,7 +186,7 @@ impl DidRegistry { let result = TransactionParser::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_RESOLVE_DID) - .parse::(&client, bytes) + .parse::(client, bytes) .map(|did_with_meta| did_with_meta.document); info!( diff --git a/indy-besu/vdr/src/contracts/did/types/did_doc.rs b/indy-besu/vdr/src/contracts/did/types/did_doc.rs index 15be01935..faa53b245 100644 --- a/indy-besu/vdr/src/contracts/did/types/did_doc.rs +++ b/indy-besu/vdr/src/contracts/did/types/did_doc.rs @@ -8,7 +8,7 @@ use log::{trace, warn}; use serde_derive::{Deserialize, Serialize}; use serde_json::{json, Value}; -pub const CONTEXT: &'static str = "https://www.w3.org/ns/did/v1"; +pub const CONTEXT: &str = "https://www.w3.org/ns/did/v1"; #[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)] pub struct DID(String); @@ -245,18 +245,18 @@ impl Default for StringOrVector { } } -impl Into for VerificationMethod { - fn into(self) -> ContractParam { +impl From for ContractParam { + fn from(value: VerificationMethod) -> Self { trace!( "VerificationMethod: {:?} convert into ContractParam has started", - self + value ); - let public_key_jwk = match self.verification_key { + let public_key_jwk = match value.verification_key { VerificationKey::JWK { ref public_key_jwk } => json!(public_key_jwk).to_string(), _ => "".to_string(), }; - let public_key_multibase = match self.verification_key { + let public_key_multibase = match value.verification_key { VerificationKey::Multibase { public_key_multibase, } => public_key_multibase, @@ -264,9 +264,9 @@ impl Into for VerificationMethod { }; let ver_method_contract_param = ContractParam::Tuple(vec![ - ContractParam::String(self.id.to_string()), - ContractParam::String(self.type_.to_string()), - ContractParam::String(self.controller.to_string()), + ContractParam::String(value.id.to_string()), + ContractParam::String(value.type_.to_string()), + ContractParam::String(value.controller.to_string()), ContractParam::String(public_key_jwk), ContractParam::String(public_key_multibase), ]); @@ -309,7 +309,7 @@ impl TryFrom for VerificationMethod { } } else if !public_key_multibase.is_empty() { VerificationKey::Multibase { - public_key_multibase: public_key_multibase.to_string(), + public_key_multibase, } } else { let vdr_error = VdrError::ContractInvalidResponseData( @@ -356,16 +356,16 @@ impl VerificationMethod { } } -impl Into for VerificationMethodOrReference { - fn into(self) -> ContractParam { +impl From for ContractParam { + fn from(value: VerificationMethodOrReference) -> Self { trace!( "VerificationMethodOrReference: {:?} convert into ContractParam has started", - self + value ); - let token = match self { + let token = match value { VerificationMethodOrReference::String(reference) => ContractParam::Tuple(vec![ - ContractParam::String(reference.to_string()), + ContractParam::String(reference), VerificationMethod::empty(), ]), VerificationMethodOrReference::VerificationMethod(verification_method) => { @@ -413,14 +413,14 @@ impl TryFrom for VerificationMethodOrReference { } } -impl Into for StringOrVector { - fn into(self) -> ContractParam { +impl From for ContractParam { + fn from(value: StringOrVector) -> Self { trace!( "StringOrVector convert into ContractParam: {:?} has started", - self + value ); - let contract_param = match self { + let contract_param = match value { StringOrVector::String(ref value) => { ContractParam::Array(vec![ContractParam::String(value.to_string())]) } @@ -434,7 +434,7 @@ impl Into for StringOrVector { trace!( "StringOrVector convert into ContractParam: {:?} has started. Result: {:?}", - self, + value, contract_param ); @@ -442,13 +442,16 @@ impl Into for StringOrVector { } } -impl Into for Service { - fn into(self) -> ContractParam { - trace!("Service: {:?} convert into ContractParam has started", self); +impl From for ContractParam { + fn from(value: Service) -> Self { + trace!( + "Service: {:?} convert into ContractParam has started", + value + ); - let (endpoint, accept, routing_keys) = match self.service_endpoint { + let (endpoint, accept, routing_keys) = match value.service_endpoint { ServiceEndpoint::String(endpoint) => ( - ContractParam::String(endpoint.to_string()), + ContractParam::String(endpoint), ContractParam::Array(vec![]), ContractParam::Array(vec![]), ), @@ -473,8 +476,8 @@ impl Into for Service { }; let service_contract_param = ContractParam::Tuple(vec![ - ContractParam::String(self.id.to_string()), - ContractParam::String(self.type_.to_string()), + ContractParam::String(value.id.to_string()), + ContractParam::String(value.type_.to_string()), endpoint, accept, routing_keys, @@ -520,59 +523,66 @@ impl TryFrom for Service { } } -impl Into for DidDocument { - fn into(self) -> ContractParam { +impl From for ContractParam { + fn from(value: DidDocument) -> Self { trace!( "DidDocument: {:?} convert into ContractParam has started", - self + value ); - let context: ContractParam = self.context.into(); - let id = ContractParam::String(self.id.value().to_string()); - let controller: ContractParam = self.controller.into(); + let context: ContractParam = value.context.into(); + let id = ContractParam::String(value.id.value().to_string()); + let controller: ContractParam = value.controller.into(); let verification_method: ContractParam = ContractParam::Array( - self.verification_method + value + .verification_method .into_iter() .map(VerificationMethod::into) .collect(), ); let authentication: ContractParam = ContractParam::Array( - self.authentication + value + .authentication .into_iter() .map(VerificationMethodOrReference::into) .collect(), ); let assertion_method: ContractParam = ContractParam::Array( - self.assertion_method + value + .assertion_method .into_iter() .map(VerificationMethodOrReference::into) .collect(), ); let capability_invocation: ContractParam = ContractParam::Array( - self.capability_invocation + value + .capability_invocation .into_iter() .map(VerificationMethodOrReference::into) .collect(), ); let capability_delegation: ContractParam = ContractParam::Array( - self.capability_delegation + value + .capability_delegation .into_iter() .map(VerificationMethodOrReference::into) .collect(), ); let key_agreement: ContractParam = ContractParam::Array( - self.key_agreement + value + .key_agreement .into_iter() .map(VerificationMethodOrReference::into) .collect(), ); let service: ContractParam = - ContractParam::Array(self.service.into_iter().map(Service::into).collect()); + ContractParam::Array(value.service.into_iter().map(Service::into).collect()); let also_known_as: ContractParam = ContractParam::Array( - self.also_known_as + value + .also_known_as .unwrap_or_default() .into_iter() - .map(|also_known_as| ContractParam::String(also_known_as)) + .map(ContractParam::String) .collect(), ); @@ -733,12 +743,12 @@ pub mod test { use super::*; use crate::utils::rand_bytes; - pub const ISSUER_ID: &'static str = "did:indy2:testnet:3LpjszkgTmE3qThge25FZw"; - pub const CONTEXT: &'static str = "https://www.w3.org/ns/did/v1"; - pub const MULTIBASE_KEY: &'static str = "zAKJP3f7BD6W4iWEQ9jwndVTCBq8ua2Utt8EEjJ6Vxsf"; - pub const SERVICE_ENDPOINT: &'static str = "https://example.com/path"; - pub const SERVICE_TYPE: &'static str = "DIDCommMessaging"; - pub const KEY_1: &'static str = "KEY-1"; + pub const ISSUER_ID: &str = "did:indy2:testnet:3LpjszkgTmE3qThge25FZw"; + pub const CONTEXT: &str = "https://www.w3.org/ns/did/v1"; + pub const MULTIBASE_KEY: &str = "zAKJP3f7BD6W4iWEQ9jwndVTCBq8ua2Utt8EEjJ6Vxsf"; + pub const SERVICE_ENDPOINT: &str = "https://example.com/path"; + pub const SERVICE_TYPE: &str = "DIDCommMessaging"; + pub const KEY_1: &str = "KEY-1"; pub fn verification_method(id: &str) -> VerificationMethod { VerificationMethod { @@ -775,7 +785,7 @@ pub mod test { } pub fn did_doc(id: Option<&str>) -> DidDocument { - let id = id.map(String::from).unwrap_or_else(|| new_id()); + let id = id.map(String::from).unwrap_or_else(new_id); DidDocument { context: StringOrVector::Vector(vec![CONTEXT.to_string()]), id: DID::new(&id), diff --git a/indy-besu/vdr/src/contracts/network/validator_control.rs b/indy-besu/vdr/src/contracts/network/validator_control.rs index d35f50b66..f2d5ed829 100644 --- a/indy-besu/vdr/src/contracts/network/validator_control.rs +++ b/indy-besu/vdr/src/contracts/network/validator_control.rs @@ -44,7 +44,7 @@ impl ValidatorControl { .add_param(validator_address.clone().try_into()?) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -82,7 +82,7 @@ impl ValidatorControl { .add_param(validator_address.clone().try_into()?) .set_type(TransactionType::Write) .set_from(from) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -107,7 +107,7 @@ impl ValidatorControl { .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_GET_VALIDATORS) .set_type(TransactionType::Read) - .build(&client); + .build(client); info!( "{} txn build has finished. Result: {:?}", @@ -139,7 +139,7 @@ impl ValidatorControl { let result = TransactionParser::new() .set_contract(Self::CONTRACT_NAME) .set_method(Self::METHOD_GET_VALIDATORS) - .parse::(&client, bytes); + .parse::(client, bytes); info!( "{} result parse has finished. Result: {:?}", diff --git a/indy-besu/vdr/src/lib.rs b/indy-besu/vdr/src/lib.rs index 487c44bfe..d7824b8f2 100644 --- a/indy-besu/vdr/src/lib.rs +++ b/indy-besu/vdr/src/lib.rs @@ -1,3 +1,4 @@ +#[allow(clippy::module_inception)] mod client; mod contracts; mod error; diff --git a/indy-besu/vdr/src/signer/basic_signer.rs b/indy-besu/vdr/src/signer/basic_signer.rs index 8c6403512..6cef092d1 100644 --- a/indy-besu/vdr/src/signer/basic_signer.rs +++ b/indy-besu/vdr/src/signer/basic_signer.rs @@ -96,10 +96,10 @@ pub mod test { pub static TRUSTEE2_ACC: Lazy
= Lazy::new(|| Address::new("0xca843569e3427144cead5e4d5999a3d0ccf92b8e")); - pub const TRUSTEE_PRIVATE_KEY: &'static str = + pub const TRUSTEE_PRIVATE_KEY: &str = "8bbbb1b345af56b560a5b20bd4b0ed1cd8cc9958a16262bc75118453cb546df7"; - pub const TRUSTEE2_PRIVATE_KEY: &'static str = + pub const TRUSTEE2_PRIVATE_KEY: &str = "4762e04d10832808a0aebdaa79c12de54afbe006bfffd228b3abcc494fe986f9"; pub fn basic_signer() -> BasicSigner {