Skip to content

Commit

Permalink
chore: refactor AccountId
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Oct 25, 2023
1 parent b075f5a commit ff45187
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
19 changes: 19 additions & 0 deletions src/model/types/account_id.rs
Original file line number Diff line number Diff line change
@@ -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<str>
);

impl From<String> 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()))
}
}
25 changes: 3 additions & 22 deletions src/model/types.rs → src/model/types/mod.rs
Original file line number Diff line number Diff line change
@@ -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<str>
);

impl From<String> 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 {
Expand Down

0 comments on commit ff45187

Please sign in to comment.