Skip to content

Commit

Permalink
fix IdentityStrategy and lints
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Nov 26, 2024
1 parent 1d55a7a commit 6f45466
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub async fn create_client(
None => EncryptedMessageStore::new_unencrypted(storage_option).await?,
};
log::info!("Creating XMTP client");
let identity_strategy = IdentityStrategy::CreateIfNotFound(
let identity_strategy = IdentityStrategy::new(
inbox_id.clone(),
account_address.clone(),
nonce,
Expand Down
2 changes: 1 addition & 1 deletion bindings_node/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const createClient = async (user: User) => {
user.account.address,
undefined,
undefined,
{ level: 'trace', structured: true }
{ level: 'info' }
)
}

Expand Down
2 changes: 1 addition & 1 deletion bindings_wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub async fn create_client(
.map_err(|_| JsError::new("Error creating unencrypted message store"))?,
};

let identity_strategy = IdentityStrategy::CreateIfNotFound(
let identity_strategy = IdentityStrategy::new(
inbox_id.clone(),
account_address.clone().to_lowercase(),
// this is a temporary solution
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ where
let inbox_id = generate_inbox_id(&w.get_address(), &nonce)?;
let client = create_client(
cli,
IdentityStrategy::CreateIfNotFound(inbox_id, w.get_address(), nonce, None),
IdentityStrategy::new(inbox_id, w.get_address(), nonce, None),
client,
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion xmtp_debug/src/app/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn new_client_inner(
dir.join(db_name)
};

let client = crate::DbgClient::builder(IdentityStrategy::CreateIfNotFound(
let client = crate::DbgClient::builder(IdentityStrategy::new(
inbox_id,
wallet.get_address(),
nonce,
Expand Down
36 changes: 17 additions & 19 deletions xmtp_mls/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub(crate) mod tests {
IdentityStrategyTestCase {
strategy: {
let (legacy_key, legacy_account_address) = generate_random_legacy_key().await;
IdentityStrategy::CreateIfNotFound(
IdentityStrategy::new(
generate_inbox_id(&legacy_account_address, &1).unwrap(),
legacy_account_address.clone(),
1,
Expand All @@ -356,7 +356,7 @@ pub(crate) mod tests {
IdentityStrategyTestCase {
strategy: {
let (legacy_key, legacy_account_address) = generate_random_legacy_key().await;
IdentityStrategy::CreateIfNotFound(
IdentityStrategy::new(
generate_inbox_id(&legacy_account_address, &1).unwrap(),
legacy_account_address.clone(),
0,
Expand All @@ -368,7 +368,7 @@ pub(crate) mod tests {
IdentityStrategyTestCase {
strategy: {
let (legacy_key, legacy_account_address) = generate_random_legacy_key().await;
IdentityStrategy::CreateIfNotFound(
IdentityStrategy::new(
generate_inbox_id(&legacy_account_address, &0).unwrap(),
legacy_account_address.clone(),
0,
Expand All @@ -381,7 +381,7 @@ pub(crate) mod tests {
IdentityStrategyTestCase {
strategy: {
let account_address = generate_local_wallet().get_address();
IdentityStrategy::CreateIfNotFound(
IdentityStrategy::new(
generate_inbox_id(&account_address, &1).unwrap(),
account_address.clone(),
0,
Expand All @@ -394,7 +394,7 @@ pub(crate) mod tests {
strategy: {
let nonce = 1;
let account_address = generate_local_wallet().get_address();
IdentityStrategy::CreateIfNotFound(
IdentityStrategy::new(
generate_inbox_id(&account_address, &nonce).unwrap(),
account_address.clone(),
nonce,
Expand All @@ -407,7 +407,7 @@ pub(crate) mod tests {
strategy: {
let nonce = 0;
let account_address = generate_local_wallet().get_address();
IdentityStrategy::CreateIfNotFound(
IdentityStrategy::new(
generate_inbox_id(&account_address, &nonce).unwrap(),
account_address.clone(),
nonce,
Expand Down Expand Up @@ -450,7 +450,7 @@ pub(crate) mod tests {
let id = generate_inbox_id(&legacy_account_address, &0).unwrap();
println!("{}", id.len());

let identity_strategy = IdentityStrategy::CreateIfNotFound(
let identity_strategy = IdentityStrategy::new(
generate_inbox_id(&legacy_account_address, &0).unwrap(),
legacy_account_address.clone(),
0,
Expand Down Expand Up @@ -483,7 +483,7 @@ pub(crate) mod tests {
assert!(client1.inbox_id() == client2.inbox_id());
assert!(client1.installation_public_key() == client2.installation_public_key());

let client3 = ClientBuilder::new(IdentityStrategy::CreateIfNotFound(
let client3 = ClientBuilder::new(IdentityStrategy::new(
generate_inbox_id(&legacy_account_address, &0).unwrap(),
legacy_account_address.to_string(),
0,
Expand All @@ -499,7 +499,7 @@ pub(crate) mod tests {
assert!(client1.inbox_id() == client3.inbox_id());
assert!(client1.installation_public_key() == client3.installation_public_key());

let client4 = ClientBuilder::new(IdentityStrategy::CreateIfNotFound(
let client4 = ClientBuilder::new(IdentityStrategy::new(
generate_inbox_id(&legacy_account_address, &0).unwrap(),
legacy_account_address.to_string(),
0,
Expand Down Expand Up @@ -548,8 +548,7 @@ pub(crate) mod tests {

let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default());

let identity =
IdentityStrategy::CreateIfNotFound("other_inbox_id".to_string(), address, nonce, None);
let identity = IdentityStrategy::new("other_inbox_id".to_string(), address, nonce, None);
assert!(matches!(
identity
.initialize_identity(&wrapper, &store, &scw_verifier)
Expand Down Expand Up @@ -590,7 +589,7 @@ pub(crate) mod tests {

let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default());

let identity = IdentityStrategy::CreateIfNotFound(inbox_id.clone(), address, nonce, None);
let identity = IdentityStrategy::new(inbox_id.clone(), address, nonce, None);
assert!(dbg!(
identity
.initialize_identity(&wrapper, &store, &scw_verifier)
Expand Down Expand Up @@ -629,7 +628,7 @@ pub(crate) mod tests {

stored.store(&store.conn().unwrap()).unwrap();
let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default());
let identity = IdentityStrategy::CreateIfNotFound(inbox_id.clone(), address, nonce, None);
let identity = IdentityStrategy::new(inbox_id.clone(), address, nonce, None);
assert!(identity
.initialize_identity(&wrapper, &store, &scw_verifier)
.await
Expand Down Expand Up @@ -669,8 +668,7 @@ pub(crate) mod tests {
let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default());

let inbox_id = "inbox_id".to_string();
let identity =
IdentityStrategy::CreateIfNotFound(inbox_id.clone(), address.clone(), nonce, None);
let identity = IdentityStrategy::new(inbox_id.clone(), address.clone(), nonce, None);
let err = identity
.initialize_identity(&wrapper, &store, &scw_verifier)
.await
Expand All @@ -695,7 +693,7 @@ pub(crate) mod tests {

let nonce = 1;
let inbox_id = generate_inbox_id(&wallet.get_address(), &nonce).unwrap();
let client_a = Client::builder(IdentityStrategy::CreateIfNotFound(
let client_a = Client::builder(IdentityStrategy::new(
inbox_id.clone(),
wallet.get_address(),
nonce,
Expand All @@ -719,7 +717,7 @@ pub(crate) mod tests {
.await
.unwrap();

let client_b = Client::builder(IdentityStrategy::CreateIfNotFound(
let client_b = Client::builder(IdentityStrategy::new(
inbox_id,
wallet.get_address(),
nonce,
Expand All @@ -743,7 +741,7 @@ pub(crate) mod tests {
// EncryptedMessageStore::new_unencrypted(StorageOption::Persistent(tmpdb.clone()))
// .unwrap();

// ClientBuilder::new(IdentityStrategy::CreateIfNotFound(
// ClientBuilder::new(IdentityStrategy::new(
// generate_local_wallet().get_address(),
// None,
// ))
Expand Down Expand Up @@ -805,7 +803,7 @@ pub(crate) mod tests {
let account_address = format!("{scw_addr:?}");
let account_id = AccountId::new_evm(anvil_meta.chain_id, account_address.clone());

let identity_strategy = IdentityStrategy::CreateIfNotFound(
let identity_strategy = IdentityStrategy::new(
generate_inbox_id(&account_address, &0).unwrap(),
account_address,
0,
Expand Down
4 changes: 2 additions & 2 deletions xmtp_mls/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ pub enum IdentityStrategy {
}

impl IdentityStrategy {
pub fn inbox_id<'a>(&'a self) -> Option<InboxIdRef<'a>> {
pub fn inbox_id(&self) -> Option<InboxIdRef<'_>> {
use IdentityStrategy::*;
match self {
CreateIfNotFound { ref inbox_id, .. } => Some(inbox_id),
_ => None,
}
}

/// Create a new Identity Strategy.
/// Create a new Identity Strategy, with [`IdentityStrategy::CreateIfNotFound`].
/// If an Identity is not found in the local store, creates a new one.
pub fn new(
inbox_id: InboxId,
Expand Down
6 changes: 3 additions & 3 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,9 @@ impl std::fmt::Display for ConversationType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use ConversationType::*;
match self {
Group => write!(f, "{}", "group"),
Dm => write!(f, "{}", "dm"),
Sync => write!(f, "{}", "sync"),
Group => write!(f, "group"),
Dm => write!(f, "dm"),
Sync => write!(f, "sync"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions xmtp_mls/src/utils/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ where
let nonce = 1;
let inbox_id = generate_inbox_id(&owner.get_address(), &nonce).unwrap();

let client = Client::<A>::builder(IdentityStrategy::CreateIfNotFound(
let client = Client::<A>::builder(IdentityStrategy::new(
inbox_id,
owner.get_address(),
nonce,
Expand Down Expand Up @@ -208,7 +208,7 @@ where
let nonce = 1;
let inbox_id = generate_inbox_id(&owner.get_address(), &nonce).unwrap();

let mut builder = Client::<A, V>::builder(IdentityStrategy::CreateIfNotFound(
let mut builder = Client::<A, V>::builder(IdentityStrategy::new(
inbox_id,
owner.get_address(),
nonce,
Expand Down

0 comments on commit 6f45466

Please sign in to comment.