Skip to content

Commit

Permalink
Add guid function to premint trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ligustah committed Apr 3, 2024
1 parent 0ff0791 commit 0f69278
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/premints/zora_premint_v2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl Premint for ZoraPremintV2 {
}
}

fn guid(&self) -> String {
format!("{:?}:{:?}:{:?}:{:?}", self.chain_id, self.collection_address, self.premint.uid, self.premint.version)
}

fn check_filter(chain_id: u64) -> Option<Filter> {
let supported_chains = [7777777, 8423]; // TODO: add the rest here and enable testnet mode
if !supported_chains.contains(&chain_id) {
Expand Down
3 changes: 2 additions & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ impl PremintStorage {
let collection_address = format!("{:?}", metadata.collection_address);
let token_id = metadata.token_id.to_string();
let chain_id = metadata.chain_id.to::<i64>();
let id = premint.guid();
sqlx::query!(
r#"
INSERT INTO premints (id, kind, signer, chain_id, collection_address, token_id, json)
VALUES (?, ?, ?, ?, ?, ?, ?)
"#,
metadata.id,
id,
metadata.kind.0,
signer,
chain_id,
Expand Down
14 changes: 14 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct PremintMetadata {
pub trait Premint: Serialize + DeserializeOwned + Debug + Clone {
fn metadata(&self) -> PremintMetadata;

fn guid(&self) -> String;

// async fn validate(&self, engine: RulesEngine<Self>) -> bool {
// engine.validate(self).await
// }
Expand Down Expand Up @@ -75,6 +77,13 @@ impl PremintTypes {
PremintTypes::ZoraV2(p) => p.metadata(),
}
}

pub fn guid(&self) -> String {
match self {
PremintTypes::Simple(p) => p.guid(),
PremintTypes::ZoraV2(p) => p.guid(),
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
Expand All @@ -99,6 +108,11 @@ impl Premint for SimplePremint {
}
}

fn guid(&self) -> String {
// TODO: make something slightly more unique
format!("{:?}:{:?}:{:?}", self.chain_id, self.sender, self.token_id)
}

fn check_filter(chain_id: u64) -> Option<Filter> {
todo!()
}
Expand Down

0 comments on commit 0f69278

Please sign in to comment.