Skip to content

Commit

Permalink
Merge pull request #217 from holaplex/main
Browse files Browse the repository at this point in the history
Release 9/7
  • Loading branch information
kespinola authored Sep 7, 2023
2 parents c702183 + 1e61150 commit 2a5ab76
Show file tree
Hide file tree
Showing 30 changed files with 808 additions and 355 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: 1.71.0
toolchain: nightly-2022-12-11
override: true
components: rustfmt, clippy

Expand Down
35 changes: 8 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ strum = { version = "0.24.1", features = ["derive"] }

[dependencies.hub-core]
package = "holaplex-hub-core"
version = "0.5.1"
version = "0.5.3"
git = "https://github.com/holaplex/hub-core"
branch = "master"
branch = "stable"
features = ["kafka", "credits", "asset_proxy", "sea-orm"]

[build-dependencies.hub-core-build]
Expand Down
12 changes: 6 additions & 6 deletions api/proto.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ sha512 = "d75800df0d4744c6b0f4d9a9952d3bfd0bb6b24a8babd19104cc11b54a525f85551b3c

[[schemas]]
subject = "nfts"
version = 26
sha512 = "8191626dbd6e222f24914589a77855e5f0f5122b7adc655ef7e84af0d9ef104715408db97cdf7843882aaa65cfcacc436a01e01b336f6758b0863ec5e007b709"
version = 27
sha512 = "ec52dffa482eb3beb72b1ae1745f3b8cb1b6d321d20fdc30078f4362c924b0f75ebe3dc53c54e5de92ea55163b64f09fe4e2b749c1bc5bc64d92f8356835eb90"

[[schemas]]
subject = "organization"
Expand All @@ -20,8 +20,8 @@ sha512 = "c5ddf43d2958ec690ee2261d0ff9808b67ce810d2fc4b6077f96f561929a920f03509f

[[schemas]]
subject = "solana_nfts"
version = 9
sha512 = "312a84e8ae8b9222c7ec2b307d036dae0bd8dac4363e813c2fcffd5d7fba8741bd802953b1ec0a96baf57a7ce852debb724fcccf3b0bd8a27a9e4cc60344a56f"
version = 10
sha512 = "1bcb166ab5dfdf4841d60caa07a4098dcec03d7e3b0e63adb090ed2f5fe990c1e13826867e8df7521ec631027d5a931a08865fd2cf2daa905807c4b7dca40213"

[[schemas]]
subject = "timestamp"
Expand All @@ -30,5 +30,5 @@ sha512 = "d167e0a143c813073eef8597f0b237e5a8eaf32abbf709724e8071b2dd73ce0438b82f

[[schemas]]
subject = "treasury"
version = 21
sha512 = "734cff313b8b4854b9a4c03cfd6f95f07b1fd86f8678393ab466443d9da4d6e7c9fc400bdbcc718d83e6c7711857941d4b6dc0ea5d1d926f05a7859a65a15509"
version = 22
sha512 = "bde788b07f818aa52e684dcbd91e1f1e3db82f242f616ec2a42ab6d412df33a1461677c229f2f9bae345938c2f325e6332a95caef2c7e01a47531af53e39bf03"
6 changes: 3 additions & 3 deletions api/proto.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ endpoint = "https://schemas.holaplex.tools"

[schemas]
organization = 5
nfts = 26
nfts = 27
customer = 2
treasury = 21
solana_nfts = 9
treasury = 22
solana_nfts = 10
polygon_nfts = 6
timestamp = 1
9 changes: 8 additions & 1 deletion api/src/blockchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ pub mod solana;

use hub_core::anyhow::Result;

use crate::proto::{NftEventKey, RetryUpdateSolanaMintPayload, UpdateSolanaMintPayload};
use crate::proto::{
NftEventKey, RetryUpdateSolanaMintPayload, SwitchCollectionPayload, UpdateSolanaMintPayload,
};

/// Represents a response from a transaction on the blockchain. This struct
/// provides the serialized message and the signatures of the signed message.
Expand Down Expand Up @@ -41,6 +43,11 @@ pub trait CollectionEvent<A, B, C> {
key: NftEventKey,
payload: RetryUpdateSolanaMintPayload,
) -> Result<()>;
async fn switch_collection(
&self,
key: NftEventKey,
payload: SwitchCollectionPayload,
) -> Result<()>;
}

#[async_trait::async_trait]
Expand Down
20 changes: 17 additions & 3 deletions api/src/blockchains/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use crate::proto::{
nft_events::Event::{
SolanaCreateCollection, SolanaCreateDrop, SolanaMintDrop, SolanaMintToCollection,
SolanaRetryCreateCollection, SolanaRetryDrop, SolanaRetryMintDrop,
SolanaRetryMintToCollection, SolanaRetryUpdatedCollectionMint, SolanaTransferAsset,
SolanaUpdateCollection, SolanaUpdateDrop, SolanaUpdatedCollectionMint,
SolanaRetryMintToCollection, SolanaRetryUpdatedCollectionMint,
SolanaSwitchMintCollectionRequested, SolanaTransferAsset, SolanaUpdateCollection,
SolanaUpdateDrop, SolanaUpdatedCollectionMint,
},
MetaplexMasterEditionTransaction, MintMetaplexEditionTransaction,
MintMetaplexMetadataTransaction, NftEventKey, NftEvents, RetryUpdateSolanaMintPayload,
TransferMetaplexAssetTransaction, UpdateSolanaMintPayload,
SwitchCollectionPayload, TransferMetaplexAssetTransaction, UpdateSolanaMintPayload,
};
#[derive(Clone)]
pub struct Solana {
Expand Down Expand Up @@ -240,4 +241,17 @@ impl
self.producer.send(Some(&event), Some(&key)).await?;
Ok(())
}

async fn switch_collection(
&self,
key: NftEventKey,
payload: SwitchCollectionPayload,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaSwitchMintCollectionRequested(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;
Ok(())
}
}
8 changes: 4 additions & 4 deletions api/src/dataloaders/collection_mints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result};
use poem::async_trait;
use sea_orm::prelude::*;

use crate::{db::Connection, entities::collection_mints};
use crate::{db::Connection, entities::collection_mints, objects::CollectionMint};

#[derive(Debug, Clone)]
pub struct Loader {
Expand All @@ -21,7 +21,7 @@ impl Loader {
#[async_trait]
impl DataLoader<Uuid> for Loader {
type Error = FieldError;
type Value = Vec<collection_mints::CollectionMint>;
type Value = Vec<CollectionMint>;

async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> {
let collection_mints = collection_mints::Entity::find()
Expand Down Expand Up @@ -60,7 +60,7 @@ impl OwnerLoader {
#[async_trait]
impl DataLoader<String> for OwnerLoader {
type Error = FieldError;
type Value = Vec<collection_mints::CollectionMint>;
type Value = Vec<CollectionMint>;

async fn load(&self, keys: &[String]) -> Result<HashMap<String, Self::Value>, Self::Error> {
let collection_mints = collection_mints::Entity::find()
Expand Down Expand Up @@ -100,7 +100,7 @@ impl CollectionMintLoader {
#[async_trait]
impl DataLoader<Uuid> for CollectionMintLoader {
type Error = FieldError;
type Value = collection_mints::CollectionMint;
type Value = CollectionMint;

async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> {
let collection_mints = collection_mints::Entity::find()
Expand Down
2 changes: 2 additions & 0 deletions api/src/dataloaders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod mint_histories;
mod nft_transfers;
mod project_collection;
mod project_collections;
mod switch_collection_histories;
mod update_histories;

pub use collection::Loader as CollectionLoader;
Expand All @@ -34,4 +35,5 @@ pub use mint_histories::{
pub use nft_transfers::CollectionMintTransfersLoader;
pub use project_collection::ProjectCollectionLoader;
pub use project_collections::ProjectCollectionsLoader;
pub use switch_collection_histories::SwitchCollectionHistoryLoader;
pub use update_histories::UpdateMintHistoryLoader;
50 changes: 50 additions & 0 deletions api/src/dataloaders/switch_collection_histories.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::collections::HashMap;

use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result};
use poem::async_trait;
use sea_orm::{prelude::*, Order, QueryOrder};

use crate::{db::Connection, entities::switch_collection_histories};

#[derive(Debug, Clone)]
pub struct SwitchCollectionHistoryLoader {
pub db: Connection,
}

impl SwitchCollectionHistoryLoader {
#[must_use]
pub fn new(db: Connection) -> Self {
Self { db }
}
}

#[async_trait]
impl DataLoader<Uuid> for SwitchCollectionHistoryLoader {
type Error = FieldError;
type Value = Vec<switch_collection_histories::Model>;

async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> {
let conn = self.db.get();
let switch_histories = switch_collection_histories::Entity::find()
.filter(
switch_collection_histories::Column::CollectionMintId
.is_in(keys.iter().map(ToOwned::to_owned)),
)
.order_by(switch_collection_histories::Column::CreatedAt, Order::Desc)
.all(conn)
.await?;

Ok(switch_histories.into_iter().fold(
HashMap::new(),
|mut acc: HashMap<Uuid, Vec<switch_collection_histories::Model>>, switch_history| {
acc.entry(switch_history.collection_mint_id.clone())
.or_insert_with(Vec::new);

acc.entry(switch_history.collection_mint_id.clone())
.and_modify(|switch_histories| switch_histories.push(switch_history.into()));

acc
},
))
}
}
Loading

0 comments on commit 2a5ab76

Please sign in to comment.