Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Jul 26, 2023
1 parent bf1deca commit 167f150
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 54 deletions.
7 changes: 4 additions & 3 deletions consumer/src/asset_api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use std::collections::HashMap;

use solana_program::pubkey::Pubkey;
Expand Down Expand Up @@ -48,9 +49,9 @@ impl From<Base58> for Pubkey {
}
}

impl ToString for Base58 {
fn to_string(&self) -> String {
Pubkey::new(&self.0).to_string()
impl fmt::Display for Base58 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&bs58::encode(&self.0).into_string())
}
}

Expand Down
92 changes: 41 additions & 51 deletions consumer/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use holaplex_hub_nfts_solana_core::{
Collection, Services,
};
use holaplex_hub_nfts_solana_entity::{collection_mints, collections, prelude::CollectionMints};
use hub_core::{chrono::Utc, prelude::*, producer::Producer, tokio, util::DebugShim, uuid::Uuid};
use hub_core::{chrono::Utc, prelude::*, producer::Producer, util::DebugShim, uuid::Uuid};
use mpl_token_metadata::pda::{find_master_edition_account, find_metadata_account};
use spl_associated_token_account::get_associated_token_address;

Expand All @@ -27,11 +27,7 @@ pub struct Processor {
}

impl Processor {
pub fn new(
solana: Solana,
db: db::Connection,
producer: Producer<SolanaNftEvents>,
) -> Self {
pub fn new(solana: Solana, db: db::Connection, producer: Producer<SolanaNftEvents>) -> Self {
Self {
solana: DebugShim(solana),
db,
Expand Down Expand Up @@ -68,7 +64,7 @@ impl Processor {

let rpc = &self.solana.0.asset_rpc();
let db = &self.db;
let producer = &self.producer;

let mut page = 1;

let collection = rpc.get_asset(&mint_address).await?;
Expand Down Expand Up @@ -176,18 +172,15 @@ impl Processor {
let (metadata_pubkey, _) = find_metadata_account(&mint);

let (master_edition, _) = find_master_edition_account(&mint);
let collection_model = Collection::create(
db,
collections::ActiveModel {
master_edition: Set(master_edition.to_string()),
update_authority: Set(update_authority.to_string()),
associated_token_account: Set(ata.to_string()),
owner: Set(owner.to_string()),
mint: Set(mint.to_string()),
metadata: Set(metadata_pubkey.to_string()),
..Default::default()
},
)
let collection_model = Collection::create(db, collections::ActiveModel {
master_edition: Set(master_edition.to_string()),
update_authority: Set(update_authority.to_string()),
associated_token_account: Set(ata.to_string()),
owner: Set(owner.to_string()),
mint: Set(mint.to_string()),
metadata: Set(metadata_pubkey.to_string()),
..Default::default()
})
.await?;

producer
Expand Down Expand Up @@ -230,7 +223,6 @@ impl Processor {
collection: Uuid,
asset: Asset,
) -> Result<collection_mints::Model> {
let db = &self.db;
let producer = self.producer.clone();
let owner = asset.ownership.owner.into();

Expand Down Expand Up @@ -284,37 +276,35 @@ impl Processor {
created_at: Utc::now().naive_utc(),
};

tokio::spawn(async move {
producer
.send(
Some(&SolanaNftEvents {
event: Some(SolanaNftEvent::ImportedExternalMint(SolanaMintPayload {
collection_id: collection.to_string(),
mint_address: mint.to_string(),
owner: owner.to_string(),
seller_fee_basis_points,
compressed: asset.compression.compressed,
creators,
metadata: Some(Metadata {
name: metadata.name,
description: metadata.description,
symbol: metadata.symbol,
attributes,
uri: asset.content.json_uri,
image,
}),
files,
update_authority: update_authority.to_string(),
})),
}),
Some(&SolanaNftEventKey {
id: uuid.to_string(),
user_id,
project_id,
}),
)
.await
});
producer
.send(
Some(&SolanaNftEvents {
event: Some(SolanaNftEvent::ImportedExternalMint(SolanaMintPayload {
collection_id: collection.to_string(),
mint_address: mint.to_string(),
owner: owner.to_string(),
seller_fee_basis_points,
compressed: asset.compression.compressed,
creators,
metadata: Some(Metadata {
name: metadata.name,
description: metadata.description,
symbol: metadata.symbol,
attributes,
uri: asset.content.json_uri,
image,
}),
files,
update_authority: update_authority.to_string(),
})),
}),
Some(&SolanaNftEventKey {
id: uuid.to_string(),
user_id,
project_id,
}),
)
.await?;

Ok(mint_model)
}
Expand Down

0 comments on commit 167f150

Please sign in to comment.