From 0f692781c4150218f25506a7a43b51b0a3082825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bierlein?= Date: Wed, 3 Apr 2024 19:04:21 +0200 Subject: [PATCH] Add guid function to premint trait --- src/premints/zora_premint_v2/types.rs | 4 ++++ src/storage.rs | 3 ++- src/types.rs | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/premints/zora_premint_v2/types.rs b/src/premints/zora_premint_v2/types.rs index 247ff3e..665a65b 100644 --- a/src/premints/zora_premint_v2/types.rs +++ b/src/premints/zora_premint_v2/types.rs @@ -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 { let supported_chains = [7777777, 8423]; // TODO: add the rest here and enable testnet mode if !supported_chains.contains(&chain_id) { diff --git a/src/storage.rs b/src/storage.rs index acfa01e..59c6e6e 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -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::(); + 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, diff --git a/src/types.rs b/src/types.rs index c1ee553..c23bb18 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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) -> bool { // engine.validate(self).await // } @@ -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)] @@ -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 { todo!() }