From ff451873507f9009fa940ee70b217f0f16011f92 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 25 Oct 2023 16:40:10 -0400 Subject: [PATCH] chore: refactor AccountId --- src/model/types/account_id.rs | 19 +++++++++++++++++++ src/model/{types.rs => types/mod.rs} | 25 +++---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 src/model/types/account_id.rs rename src/model/{types.rs => types/mod.rs} (69%) diff --git a/src/model/types/account_id.rs b/src/model/types/account_id.rs new file mode 100644 index 00000000..5d0b8c04 --- /dev/null +++ b/src/model/types/account_id.rs @@ -0,0 +1,19 @@ +use {relay_rpc::new_type, std::sync::Arc}; + +new_type!( + #[doc = "A CAIP-10 account ID which is guaranteed to be lowercase to avoid ERC-55 duplicates."] + #[as_ref(forward)] + AccountId: Arc +); + +impl From for AccountId { + fn from(s: String) -> Self { + Self(Arc::from(s.to_ascii_lowercase())) + } +} + +impl From<&str> for AccountId { + fn from(s: &str) -> Self { + Self(Arc::from(s.to_ascii_lowercase())) + } +} diff --git a/src/model/types.rs b/src/model/types/mod.rs similarity index 69% rename from src/model/types.rs rename to src/model/types/mod.rs index c93b70ed..78c42e9b 100644 --- a/src/model/types.rs +++ b/src/model/types/mod.rs @@ -1,33 +1,14 @@ use { chrono::{DateTime, Utc}, - relay_rpc::{ - domain::{ProjectId, Topic}, - new_type, - }, + relay_rpc::domain::{ProjectId, Topic}, sqlx::FromRow, - std::sync::Arc, uuid::Uuid, }; // See /migrations/ERD.md -new_type!( - #[doc = "Represents a CAIP-10 account ID."] - #[as_ref(forward)] - AccountId: Arc -); - -impl From for AccountId { - fn from(s: String) -> Self { - Self(Arc::from(s.to_ascii_lowercase())) - } -} - -impl From<&str> for AccountId { - fn from(s: &str) -> Self { - Self(Arc::from(s.to_ascii_lowercase())) - } -} +mod account_id; +pub use account_id::*; #[derive(Debug, FromRow)] pub struct Project {