Skip to content

Commit

Permalink
Merge pull request #81 from holaplex/abdul/use-nonblocking
Browse files Browse the repository at this point in the history
use non blocking solana rpc client
  • Loading branch information
kespinola committed Oct 12, 2023
2 parents 40412c4 + a69cd38 commit e39b3ed
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 36 deletions.
15 changes: 9 additions & 6 deletions consumer/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,43 @@ impl<A> From<TransactionResponse<A>> for SolanaPendingTransaction {
}
}

#[async_trait]
pub trait CollectionBackend {
fn create(
async fn create(
&self,
txn: MetaplexMasterEditionTransaction,
) -> Result<TransactionResponse<MasterEditionAddresses>>;

fn update(
async fn update(
&self,
collection: &collections::Model,
txn: MetaplexMasterEditionTransaction,
) -> Result<TransactionResponse<UpdateMasterEditionAddresses>>;

fn update_mint(
async fn update_mint(
&self,
collection: &collections::Model,
mint: &collection_mints::Model,
txn: UpdateSolanaMintPayload,
) -> Result<TransactionResponse<UpdateCollectionMintAddresses>>;

fn retry_update_mint(
async fn retry_update_mint(
&self,
revision: &update_revisions::Model,
) -> Result<TransactionResponse<UpdateCollectionMintAddresses>>;

fn switch(
async fn switch(
&self,
mint: &collection_mints::Model,
collection: &collections::Model,
new_collection: &collections::Model,
) -> Result<TransactionResponse<SwitchCollectionAddresses>>;
}

#[async_trait]
pub trait MintBackend<T, R> {
fn mint(&self, collection: &collections::Model, txn: T) -> Result<TransactionResponse<R>>;
async fn mint(&self, collection: &collections::Model, txn: T)
-> Result<TransactionResponse<R>>;
}

#[async_trait]
Expand Down
16 changes: 14 additions & 2 deletions consumer/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl EventKind {

let address = if let Some(compression_leaf) = compression_leafs {
let signature = Signature::from_str(&signature)?;
let nonce = solana.extract_compression_nonce(&signature)?;
let nonce = solana.extract_compression_nonce(&signature).await?;

let asset_id = mpl_bubblegum::utils::get_asset_id(
&Pubkey::from_str(&compression_leaf.merkle_tree)?,
Expand Down Expand Up @@ -765,7 +765,7 @@ impl Processor {
.map_err(|k| ProcessorError::new(k, kind, ErrorSource::TreasuryStatus));
}

let res = match self.solana().submit_transaction(&res) {
let res = match self.solana().submit_transaction(&res).await {
Ok(sig) => self
.event_submitted(kind, &key, sig)
.await
Expand Down Expand Up @@ -834,6 +834,7 @@ impl Processor {
let conn = self.db.get();
let tx = backend
.create(payload.clone())
.await
.map_err(ProcessorErrorKind::Solana)?;

let MasterEditionAddresses {
Expand Down Expand Up @@ -880,6 +881,7 @@ impl Processor {

let tx = backend
.mint(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let compression_leaf = compression_leafs::Model {
Expand Down Expand Up @@ -910,6 +912,7 @@ impl Processor {

let tx = backend
.mint(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let collection_mint = collection_mints::Model {
Expand Down Expand Up @@ -949,6 +952,7 @@ impl Processor {

let tx = backend
.mint(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let collection_mint = collection_mints::Model {
Expand Down Expand Up @@ -979,6 +983,7 @@ impl Processor {

let tx = backend
.update(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

Ok(tx.into())
Expand All @@ -1000,6 +1005,7 @@ impl Processor {

let tx = backend
.update_mint(&collection, &mint, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let UpdateCollectionMintAddresses {
Expand Down Expand Up @@ -1035,6 +1041,7 @@ impl Processor {

let tx = backend
.retry_update_mint(&revision)
.await
.map_err(ProcessorErrorKind::Solana)?;

Ok(tx.into())
Expand Down Expand Up @@ -1083,6 +1090,7 @@ impl Processor {
let conn = self.db.get();
let tx = backend
.create(payload.clone())
.await
.map_err(ProcessorErrorKind::Solana)?;

let MasterEditionAddresses {
Expand Down Expand Up @@ -1133,6 +1141,7 @@ impl Processor {

let tx = backend
.switch(&mint, &collection, &new_collection)
.await
.map_err(ProcessorErrorKind::Solana)?;

Ok(tx.into())
Expand All @@ -1157,6 +1166,7 @@ impl Processor {

let tx = backend
.mint(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let MintEditionAddresses {
Expand Down Expand Up @@ -1196,6 +1206,7 @@ impl Processor {

let tx = backend
.mint(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let leaf_model = CompressionLeaf::find_by_id(conn, id)
Expand All @@ -1218,6 +1229,7 @@ impl Processor {

let tx = backend
.mint(&collection, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

let MintMetaplexAddresses {
Expand Down
Loading

0 comments on commit e39b3ed

Please sign in to comment.