diff --git a/src/blockfrost.rs b/src/blockfrost.rs index 2bdfa36..e4dd37e 100644 --- a/src/blockfrost.rs +++ b/src/blockfrost.rs @@ -1,11 +1,13 @@ -use crate::provider::error::DataProviderError; -use crate::models::{CDPDatum, RewardView, TokenInfoView, CardanoNativeAssetView, StakeDelegationView, DelegationView, - StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView, PoolView +use crate::models::{ + CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, PoolView, RewardView, + StakeDelegationView, StakeDeregistrationView, StakeRegistrationView, TokenInfoView, + TxHistoryListView, }; +use crate::provider::error::DataProviderError; use async_trait::async_trait; -use blockfrost::{load, BlockFrostApi}; use bigdecimal::BigDecimal; +use blockfrost::BlockFrostApi; use ::log::debug; @@ -21,24 +23,30 @@ unsafe impl Send for BlockfrostProvider {} unsafe impl Sync for BlockfrostProvider {} impl BlockfrostProvider { - pub fn new() -> Self { - let api = BlockfrostProvider::build_api().unwrap(); - BlockfrostProvider { api } + pub fn new() -> Result { + let api = BlockfrostProvider::build_api()?; + Ok(BlockfrostProvider { api }) } - fn build_api() -> blockfrost::Result { - let configurations = load::configurations_from_env()?; + fn build_api() -> Result { + let configurations = blockfrost::load::configurations_from_env()?; debug!("configurations: {:?}", configurations); - let mut blockfrost_settings = blockfrost::BlockFrostSettings::default(); - blockfrost_settings.network_address = configurations["cardano_network"].as_str().unwrap().to_owned(); + let blockfrost_settings = blockfrost::BlockFrostSettings { + network_address: configurations["cardano_network"] + .as_str() + .unwrap() + .to_owned(), + ..Default::default() + }; debug!("bfs: {:?}", blockfrost_settings); - let api = BlockFrostApi::new( - configurations["project_id"].as_str().unwrap(), - blockfrost_settings, - ); + let project_id = configurations["project_id"] + .as_str() + .ok_or_else(|| DataProviderError::Custom("project id not found".into()))?; + + let api = BlockFrostApi::new(project_id, blockfrost_settings); Ok(api) } @@ -81,10 +89,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { async fn first_transaction_from_stake_addr( &self, stake_address_in: &str, - ) -> Result< - cardano_serialization_lib::address::Address, - DataProviderError, - > { + ) -> Result { let str_addr = api::select_addr_of_first_transaction(self, stake_address_in)?; Ok(dcslc::addr_from_str(&str_addr)?) } @@ -112,23 +117,15 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { &self, tx_id: i64, tx_index: i16, - ) -> Result, DataProviderError> - { + ) -> Result, DataProviderError> { Ok(api::get_utxo_tokens(self, tx_id, tx_index)?) } - async fn active_pools( - &self, - page: usize, - ) -> Result, DataProviderError> - { + async fn active_pools(&self, page: usize) -> Result, DataProviderError> { Ok(api::active_pools(&self, page).await?) } - async fn find_datums_for_tx( - &self, - txid: &Vec, - ) -> Result, DataProviderError> { + async fn find_datums_for_tx(&self, txid: &Vec) -> Result, DataProviderError> { Ok(api::find_datums_for_tx(self, txid)?) } @@ -140,8 +137,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { &self, pool: &str, epoch: i32, - ) -> Result, DataProviderError> - { + ) -> Result, DataProviderError> { Ok(api::pool_delegations(self, pool, epoch)?) } @@ -159,11 +155,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { )?) } - async fn pool_total_staked( - &self, - pool: &str, - epoch: i32, - ) -> Result { + async fn pool_total_staked(&self, pool: &str, epoch: i32) -> Result { Ok(api::pool_total_stake(self, pool, epoch)?) } @@ -179,28 +171,21 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::fingerprint(self, policy, tokenname)?) } - async fn token_info( - &self, - fingerprint_in: &str, - ) -> Result { + async fn token_info(&self, fingerprint_in: &str) -> Result { Ok(api::token_info(self, fingerprint_in)?) } async fn stake_registration( &self, stake_addr_in: &str, - ) -> Result, DataProviderError> - { + ) -> Result, DataProviderError> { Ok(api::stake_registration(self, stake_addr_in)?) } async fn stake_deregistration( &self, stake_addr_in: &str, - ) -> Result< - Vec, - DataProviderError, - > { + ) -> Result, DataProviderError> { Ok(api::stake_deregistration(self, stake_addr_in)?) } @@ -215,37 +200,26 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { &self, fingerprint_in: &str, min_amount: Option<&i64>, - ) -> Result, DataProviderError> - { + ) -> Result, DataProviderError> { Ok(api::lookup_token_holders(self, fingerprint_in, min_amount)?) } async fn lookup_nft_token_holders( &self, policy: &str, - ) -> Result, DataProviderError> - { + ) -> Result, DataProviderError> { Ok(api::lookup_nft_token_holders(self, policy)?) } - async fn pool_valid( - &self, - pool_id: &str, - ) -> Result { + async fn pool_valid(&self, pool_id: &str) -> Result { Ok(api::pool_valid(self, pool_id)?) } - async fn txhash_spent( - &self, - txhash: &str, - ) -> Result { + async fn txhash_spent(&self, txhash: &str) -> Result { Ok(api::txhash_spent(self, txhash)?) } - async fn addresses_exist( - &self, - address: &Vec<&str>, - ) -> Result, DataProviderError> { + async fn addresses_exist(&self, address: &Vec<&str>) -> Result, DataProviderError> { Ok(api::addresses_exist(self, address).await?) } @@ -253,12 +227,11 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { &self, addresses: &Vec<&str>, slot: Option, - ) -> Result, DataProviderError> - { + ) -> Result, DataProviderError> { Ok(api::get_addresses_transactions(self, addresses, slot).await?) } - async fn retrieve_staked_amount ( + async fn retrieve_staked_amount( &self, epoch: i32, stake_addr: &str, @@ -266,7 +239,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::retrieve_staked_amount(self, epoch, stake_addr).await?) } - async fn retrieve_generated_rewards ( + async fn retrieve_generated_rewards( &self, stake_addr: &str, ) -> Result, DataProviderError> { diff --git a/src/blockfrost/api.rs b/src/blockfrost/api.rs index fc31b6b..4deb96f 100644 --- a/src/blockfrost/api.rs +++ b/src/blockfrost/api.rs @@ -1,18 +1,20 @@ -use blockfrost::{stream::StreamExt, AddressTransaction, Transaction, PoolMetadata, AccountHistory, AccountReward}; -use itertools::Itertools; +use blockfrost::{ + stream::StreamExt, AccountHistory, AccountReward, AddressTransaction, PoolMetadata, Transaction, +}; use super::error::DataProviderBlockfrostError; use super::BlockfrostProvider; use crate::models::{ - CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, StakeDelegationView, - StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, TxHistoryListView, PoolView + CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, PoolView, RewardView, + StakeDelegationView, StakeDeregistrationView, StakeRegistrationView, TokenInfoView, + TxHistoryListView, }; -use cardano_serialization_lib as csl; use crate::provider::error::DataProviderError; -use blockfrost::{AccountAddress, AddressUtxo}; -use bigdecimal::BigDecimal; use array_tool::vec::Uniq; +use bigdecimal::BigDecimal; +use blockfrost::{AccountAddress, AddressUtxo}; +use cardano_serialization_lib as csl; use log::debug; @@ -60,7 +62,8 @@ pub fn utxo_by_txid( fn bf_utxo_as_csl_utxo(address_utxo: &AddressUtxo) -> csl::utils::TransactionUnspentOutput { //debug!("C1: {:?}", address_utxo.tx_hash.clone()); let input = csl::TransactionInput::new( - &csl::crypto::TransactionHash::from_bytes(hex::decode(&address_utxo.tx_hash).unwrap()).unwrap(), + &csl::crypto::TransactionHash::from_bytes(hex::decode(&address_utxo.tx_hash).unwrap()) + .unwrap(), address_utxo.output_index, ); @@ -77,9 +80,10 @@ fn bf_utxo_as_csl_utxo(address_utxo: &AddressUtxo) -> csl::utils::TransactionUns ma.set_asset( &csl::PolicyID::from_bytes(hex::decode(hexpolicy).unwrap()).unwrap(), &csl::AssetName::new(hex::decode(hexname).unwrap()).unwrap(), - qty); + qty, + ); } - }; + } if ma.len() > 0 { cvalue.set_multiasset(&ma); } @@ -99,7 +103,6 @@ pub async fn get_address_utxos( bfp: &BlockfrostProvider, addr: &str, ) -> Result { - let mut address_utxos = Vec::::with_capacity(BLOCKFROST_FETCH_MAX_ITEMS); // TODO: See if we could fold with take_while instead of take(BLOCKFROST_FETCH_MAX_ITEMS) @@ -112,9 +115,12 @@ pub async fn get_address_utxos( // }) // .await, // ); - let mut lister = bfp.api.addresses_utxos_all(&addr).take(BLOCKFROST_FETCH_MAX_ITEMS); + let mut lister = bfp + .api + .addresses_utxos_all(&addr) + .take(BLOCKFROST_FETCH_MAX_ITEMS); while let Some(n) = lister.next().await { - let n = n.map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + let n = n.map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; if n.is_empty() { break; }; @@ -187,25 +193,26 @@ pub async fn addresses_exist( let mut exists = Vec::with_capacity(addresses.len()); for addr in addresses { exists.push(bfp.api.addresses(&addr).await.is_ok()) - }; + } Ok(exists) } - /// Get list of txs involving addresses pub async fn get_addresses_transactions( bfp: &BlockfrostProvider, addresses: &Vec<&str>, _slot: Option, ) -> Result, DataProviderBlockfrostError> { - let mut address_txs = Vec::::with_capacity(BLOCKFROST_FETCH_MAX_ITEMS); // TODO: See if we could fold with take_while instead of take(BLOCKFROST_FETCH_MAX_ITEMS) for addr in addresses { - let mut lister = bfp.api.addresses_transactions_all(&addr).take(BLOCKFROST_FETCH_MAX_ITEMS); + let mut lister = bfp + .api + .addresses_transactions_all(&addr) + .take(BLOCKFROST_FETCH_MAX_ITEMS); while let Some(n) = lister.next().await { - let n = n.map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + let n = n.map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; if n.is_empty() { break; }; @@ -213,19 +220,26 @@ pub async fn get_addresses_transactions( } } - let tx_hashes = address_txs.iter().map(|t| t.tx_hash.to_owned()).collect::>().unique(); + let tx_hashes = address_txs + .iter() + .map(|t| t.tx_hash.to_owned()) + .collect::>() + .unique(); let mut transactions = Vec::::new(); for tx_hash in tx_hashes { - let tx = bfp.api + let tx = bfp + .api .transaction_by_hash(&tx_hash) .await - .map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + .map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; transactions.push(tx); - } - let r = transactions.iter().map(|tx| TxHistoryListView::from_blockfrost_tx(tx)).collect::>(); + let r = transactions + .iter() + .map(|tx| TxHistoryListView::from_blockfrost_tx(tx)) + .collect::>(); Ok(r) } @@ -237,44 +251,44 @@ pub async fn active_pools( let mut pool_ids = Vec::::with_capacity(BLOCKFROST_FETCH_MAX_ITEMS); // TODO: See if we could fold with take_while instead of take(BLOCKFROST_FETCH_MAX_ITEMS) - let mut lister = bfp.api.pools_all().take(BLOCKFROST_FETCH_MAX_ITEMS); + let mut lister = bfp.api.pools_all().take(BLOCKFROST_FETCH_MAX_ITEMS); while let Some(n) = lister.next().await { - let n = n.map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + let n = n.map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; if n.is_empty() { break; }; pool_ids.extend(n); } - let pool_ids_page = pool_ids.chunks(50).nth(page) - .unwrap_or_default(); + let pool_ids_page = pool_ids.chunks(50).nth(page).unwrap_or_default(); let mut pools = Vec::::new(); for pool_id in pool_ids_page { - let pool_metadata = bfp.api.pools_metadata(&pool_id) + let pool_metadata = bfp + .api + .pools_metadata(&pool_id) .await - .map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + .map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; pools.push(pool_metadata); - } - let r = pools.iter().map(|pm| - PoolView { - pool_hash: pm.pool_id.clone(), - ticker: pm.ticker.as_ref().unwrap_or(&"".to_string()).clone(), - json: serde_json::json!({ - "name": pm.name.as_ref().unwrap_or(&"".to_string()).clone(), - "homepage": pm.homepage.as_ref().unwrap_or(&"".to_string()).clone(), - "description": pm.name.as_ref().unwrap_or(&"".to_string()).clone(), - }), - }) + let r = pools + .iter() + .map(|pm| PoolView { + pool_hash: pm.pool_id.clone(), + ticker: pm.ticker.as_ref().unwrap_or(&"".to_string()).clone(), + json: serde_json::json!({ + "name": pm.name.as_ref().unwrap_or(&"".to_string()).clone(), + "homepage": pm.homepage.as_ref().unwrap_or(&"".to_string()).clone(), + "description": pm.name.as_ref().unwrap_or(&"".to_string()).clone(), + }), + }) .collect::>(); Ok(r) } - pub fn find_datums_for_tx( bfp: &BlockfrostProvider, txid: &Vec, @@ -376,7 +390,9 @@ pub fn mint_metadata( // Impossible only with blockfrost, not supported querying any asset info from fingerprint // (and is not possible to get policy+assetname from fingerprint) // See https://blockfrost.dev/support/cardano#poolpm-uses-fingerprints-for-querying-assets-why-dont-you-too - Err(DataProviderBlockfrostError::Custom("Fingerprint unsupported, use policy/assetname instead".to_string())) + Err(DataProviderBlockfrostError::Custom( + "Fingerprint unsupported, use policy/assetname instead".to_string(), + )) } pub fn pool_valid( @@ -395,17 +411,19 @@ pub fn txhash_spent( Ok(false) } -pub async fn retrieve_staked_amount ( +pub async fn retrieve_staked_amount( bfp: &BlockfrostProvider, epoch: i32, stake_addr: &str, ) -> Result { - let mut account_history = Vec::::with_capacity(BLOCKFROST_FETCH_MAX_ITEMS); // TODO: See if we could fold with take_while instead of take(BLOCKFROST_FETCH_MAX_ITEMS) - let mut lister = bfp.api.accounts_history_all(stake_addr).take(BLOCKFROST_FETCH_MAX_ITEMS); + let mut lister = bfp + .api + .accounts_history_all(stake_addr) + .take(BLOCKFROST_FETCH_MAX_ITEMS); while let Some(n) = lister.next().await { - let n = n.map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + let n = n.map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; if n.is_empty() { break; }; @@ -415,7 +433,10 @@ pub async fn retrieve_staked_amount ( debug!("AC: {:?}", account_history); let i128_epoch = i128::from(epoch); - let amount = match account_history.iter().find(|h| h.active_epoch == i128_epoch) { + let amount = match account_history + .iter() + .find(|h| h.active_epoch == i128_epoch) + { Some(h) => h.amount.parse::().unwrap_or(0), None => 0, }; @@ -423,17 +444,19 @@ pub async fn retrieve_staked_amount ( Ok(BigDecimal::from(amount)) } -pub async fn retrieve_generated_rewards ( +pub async fn retrieve_generated_rewards( bfp: &BlockfrostProvider, stake_addr: &str, ) -> Result, DataProviderError> { - let mut account_rewards = Vec::::with_capacity(BLOCKFROST_FETCH_MAX_ITEMS); // TODO: See if we could fold with take_while instead of take(BLOCKFROST_FETCH_MAX_ITEMS) - let mut lister = bfp.api.accounts_rewards_all(stake_addr).take(BLOCKFROST_FETCH_MAX_ITEMS); + let mut lister = bfp + .api + .accounts_rewards_all(stake_addr) + .take(BLOCKFROST_FETCH_MAX_ITEMS); while let Some(n) = lister.next().await { - let n = n.map_err( |e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; + let n = n.map_err(|e| DataProviderBlockfrostError::GeneralError(e.to_string()))?; if n.is_empty() { break; }; @@ -442,12 +465,13 @@ pub async fn retrieve_generated_rewards ( debug!("AC: {:?}", account_rewards); - let r = account_rewards.iter().map(|h| - RewardView { - amount: h.amount.parse::().unwrap_or(0), - earned_epoch: i64::try_from(h.epoch).unwrap_or(0), - spendable_epoch: i64::try_from(h.epoch+2).unwrap_or(0), - }) + let r = account_rewards + .iter() + .map(|h| RewardView { + amount: h.amount.parse::().unwrap_or(0), + earned_epoch: i64::try_from(h.epoch).unwrap_or(0), + spendable_epoch: i64::try_from(h.epoch + 2).unwrap_or(0), + }) .collect::>(); Ok(r) diff --git a/src/config.rs b/src/config.rs index f4a0ac2..c4a8d25 100644 --- a/src/config.rs +++ b/src/config.rs @@ -144,9 +144,10 @@ impl Default for ChainWellKnownInfo { } } -#[derive(Deserialize)] +#[derive(Default, Deserialize)] #[serde(tag = "type")] pub enum ChainConfig { + #[default] Mainnet, Testnet, PreProd, @@ -154,12 +155,6 @@ pub enum ChainConfig { Custom(u64), } -impl Default for ChainConfig { - fn default() -> Self { - Self::Mainnet - } -} - impl From for ChainWellKnownInfo { fn from(other: ChainConfig) -> Self { match other { @@ -201,28 +196,25 @@ pub struct ConfigRoot { impl ConfigRoot { pub fn new(explicit_file: &Option) -> Result { - let mut s = config::Config::builder(); - - // but we can override it by having a file in the working dir - s = s.add_source(config::File::with_name("config.toml").required(false)); + let mut s = config::Config::builder() + // but we can override it by having a file in the working dir + .add_source(config::File::with_name("config.toml").required(false)); // if an explicit file was passed, then we load it as mandatory if let Some(explicit) = explicit_file.as_ref().and_then(|x| x.to_str()) { s = s.add_source(config::File::with_name(explicit).required(true)); } - // finally, we use env vars to make some last-step overrides - s = s.add_source(config::Environment::with_prefix("CONFIG").separator("_")); - - s.build()?.try_deserialize() + s.add_source(config::Environment::with_prefix("CONFIG").separator("_")) + .build()? + .try_deserialize() } pub fn set_as_env(&self) { - match self.appconfigs.clone() { - appconfigs::Config::Nft(x) => std::env::set_var("ENNFT_POLICY", x.policy_id), - appconfigs::Config::None => {} + if let appconfigs::Config::Nft(x) = &self.appconfigs { + std::env::set_var("ENNFT_POLICY", x.policy_id.clone()); } - std::env::set_var("PROVIDER", &self.connectivity.provider.as_str()); + std::env::set_var("PROVIDER", self.connectivity.provider.as_str()); std::env::set_var("DBSYNC_URL", &self.connectivity.dbsync_url); //std::env::set_var("BLOCKFROST_API_URL", &self.connectivity.blockfrost_api_url); //std::env::set_var("BLOCKFROST_PROJECT_ID", &self.connectivity.blockfrost_project_id); @@ -242,8 +234,6 @@ mod connectivity { #[serde(deserialize_with = "ProviderType::deserialize_with")] pub provider: ProviderType, pub dbsync_url: String, - // pub blockfrost_api_url: String, - // pub blockfrost_project_id: String, pub submit_endpoint_1: String, pub submit_endpoint_2: String, pub submit_endpoint_3: String, diff --git a/src/dbsync/api.rs b/src/dbsync/api.rs index 5b04ba1..0644144 100644 --- a/src/dbsync/api.rs +++ b/src/dbsync/api.rs @@ -1,5 +1,5 @@ use super::error::DataProviderDBSyncError; -use super::models::{PoolHash, PoolRetire, Rewardtype, UnspentUtxo, UtxoView}; +use super::models::{PoolHash, PoolRetire, UnspentUtxo, UtxoView}; use super::schema::*; use crate::models::{ CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, PoolView, RewardView, @@ -12,9 +12,8 @@ use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; use dcslc::TransactionUnspentOutputs; use diesel::prelude::*; use log::debug; -use std::str::FromStr; -/// get all tokens of an utxo +/// get all tokens of an utxo pub fn get_utxo_tokens( dbs: &DBSyncProvider, tx_id: i64, @@ -958,19 +957,19 @@ fn _tx_history_q( }); addresses.pop(); addresses.push(')'); - let query =format!("select + let query =format!("select distinct t.hash, min(b.slot_no) as slot, asset.fingerprint, asset.value from tx_out to2 join tx t on t.id = to2.tx_id - join block b on b.id = t.block_id + join block b on b.id = t.block_id join lateral ( - select array_agg(ma.fingerprint) as fingerprint, array_agg(mto.quantity) as value, mto.tx_out_id + select array_agg(ma.fingerprint) as fingerprint, array_agg(mto.quantity) as value, mto.tx_out_id from ma_tx_out as mto join multi_asset ma on ma.id = mto.ident where mto.tx_out_id = to2.id - group by mto.tx_out_id - ) as asset on asset.tx_out_id = to2.id + group by mto.tx_out_id + ) as asset on asset.tx_out_id = to2.id where address IN {addresses} group by t.hash, b.slot_no, asset.fingerprint, asset.value"); log::debug!("{addresses}"); @@ -998,11 +997,11 @@ pub fn tx_history( addresses.pop(); addresses.push(')'); let query = format!( - "select + "select distinct t.hash, min(b.slot_no) as slot from tx_out to2 join tx t on t.id = to2.tx_id - join block b on b.id = t.block_id + join block b on b.id = t.block_id where address IN {addresses} group by b.slot_no, t.hash order by slot desc" ); @@ -1829,9 +1828,8 @@ pub async fn epoch_change( #[cfg(test)] mod tests { - use crate::{dbsync::DataProviderDBSyncError, provider::CardanoDataProvider}; + use crate::provider::CardanoDataProvider; use bigdecimal::BigDecimal; - use itertools::Itertools; use std::str::FromStr; #[tokio::test] @@ -2021,97 +2019,202 @@ mod tests { db_path: dotenv::var("DBSYNC_DB_URL").unwrap(), })); - let utxo_tokens = super::get_txo_tokens( - dp.provider(), - 3312750, - 0 - ).unwrap(); + let utxo_tokens = super::get_txo_tokens(dp.provider(), 3312750, 0).unwrap(); assert_eq!(utxo_tokens[0].id, 125105); - assert_eq!(utxo_tokens[0].fingerprint, "asset1vyhv522fs7tg4kyky042empuaeg0e5v9aur0w0"); + assert_eq!( + utxo_tokens[0].fingerprint, + "asset1vyhv522fs7tg4kyky042empuaeg0e5v9aur0w0" + ); assert_eq!(utxo_tokens[0].quantity, BigDecimal::from(3)); - assert_eq!(hex::encode(utxo_tokens[0].policy.clone()), "4b9ae3978af62cf98dcc3b9aecc3dbbd2f59fa06b55e1f443e3c7c81"); - assert_eq!(hex::encode(utxo_tokens[0].name.clone()), "ce036a77053b02d10fecc454368896325fd2ac7f5966bb9a35fe794b7bbf850f"); - + assert_eq!( + hex::encode(utxo_tokens[0].policy.clone()), + "4b9ae3978af62cf98dcc3b9aecc3dbbd2f59fa06b55e1f443e3c7c81" + ); + assert_eq!( + hex::encode(utxo_tokens[0].name.clone()), + "ce036a77053b02d10fecc454368896325fd2ac7f5966bb9a35fe794b7bbf850f" + ); println!("utxo_tokens[0]: {:?}", utxo_tokens[0]); - let utxo_tokens = super::get_txo_tokens( - dp.provider(), - 3312750, - 1 - ).unwrap(); + let utxo_tokens = super::get_txo_tokens(dp.provider(), 3312750, 1).unwrap(); assert_eq!(utxo_tokens[0].id, 86452); - assert_eq!(utxo_tokens[0].fingerprint, "asset1gquup8evek9psft57ka29atuv9t4ekujfeulay"); + assert_eq!( + utxo_tokens[0].fingerprint, + "asset1gquup8evek9psft57ka29atuv9t4ekujfeulay" + ); assert_eq!(utxo_tokens[0].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[0].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[0].name.clone()), "079389604744f143190973559b08cc12ce044f51c56527ddb05a8d648a265f76"); + assert_eq!( + hex::encode(utxo_tokens[0].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[0].name.clone()), + "079389604744f143190973559b08cc12ce044f51c56527ddb05a8d648a265f76" + ); assert_eq!(utxo_tokens[1].id, 86839); - assert_eq!(utxo_tokens[1].fingerprint, "asset14hltlww3q8alhqznyz0t5rnz3wrpgg8762lsxk"); + assert_eq!( + utxo_tokens[1].fingerprint, + "asset14hltlww3q8alhqznyz0t5rnz3wrpgg8762lsxk" + ); assert_eq!(utxo_tokens[1].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[1].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[1].name.clone()), "466f56e732c05a5b6c0a4b72059ca0b34dfc8b2686fe870abc65ea8c28389265"); + assert_eq!( + hex::encode(utxo_tokens[1].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[1].name.clone()), + "466f56e732c05a5b6c0a4b72059ca0b34dfc8b2686fe870abc65ea8c28389265" + ); assert_eq!(utxo_tokens[2].id, 86784); - assert_eq!(utxo_tokens[2].fingerprint, "asset1xh75cc98vzh5s7hw37gzgxuaj67ark2p52lwgv"); + assert_eq!( + utxo_tokens[2].fingerprint, + "asset1xh75cc98vzh5s7hw37gzgxuaj67ark2p52lwgv" + ); assert_eq!(utxo_tokens[2].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[2].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[2].name.clone()), "52b31a059b63ce58cc129aa14979458190b45c93c0213341799d0b97d8ad69be"); + assert_eq!( + hex::encode(utxo_tokens[2].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[2].name.clone()), + "52b31a059b63ce58cc129aa14979458190b45c93c0213341799d0b97d8ad69be" + ); assert_eq!(utxo_tokens[3].id, 90128); - assert_eq!(utxo_tokens[3].fingerprint, "asset189z77fxt2h758mgth5rc6m2tavsj0s6kepwxf9"); + assert_eq!( + utxo_tokens[3].fingerprint, + "asset189z77fxt2h758mgth5rc6m2tavsj0s6kepwxf9" + ); assert_eq!(utxo_tokens[3].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[3].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[3].name.clone()), "5be074649f3657223e4d1d06eb18dc6df603459efb94c6893f8613975dbf5b8c"); + assert_eq!( + hex::encode(utxo_tokens[3].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[3].name.clone()), + "5be074649f3657223e4d1d06eb18dc6df603459efb94c6893f8613975dbf5b8c" + ); assert_eq!(utxo_tokens[4].id, 86813); - assert_eq!(utxo_tokens[4].fingerprint, "asset13nmc52yg556gpu4u53stk8fc5qfhvvyadrd78r"); + assert_eq!( + utxo_tokens[4].fingerprint, + "asset13nmc52yg556gpu4u53stk8fc5qfhvvyadrd78r" + ); assert_eq!(utxo_tokens[4].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[4].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[4].name.clone()), "6a11a2299502c640830dce1a830f4a20b3f1451edd46606d7219e7d9765caa06"); + assert_eq!( + hex::encode(utxo_tokens[4].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[4].name.clone()), + "6a11a2299502c640830dce1a830f4a20b3f1451edd46606d7219e7d9765caa06" + ); assert_eq!(utxo_tokens[5].id, 86365); - assert_eq!(utxo_tokens[5].fingerprint, "asset10n9gjx0h40un2tl5wpx5dr4h0zg8yqkdc7u468"); + assert_eq!( + utxo_tokens[5].fingerprint, + "asset10n9gjx0h40un2tl5wpx5dr4h0zg8yqkdc7u468" + ); assert_eq!(utxo_tokens[5].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[5].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[5].name.clone()), "6c541e3e0ff73ca23a543d372e7455989c29a2df8b55496890e3f00418f64a97"); + assert_eq!( + hex::encode(utxo_tokens[5].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[5].name.clone()), + "6c541e3e0ff73ca23a543d372e7455989c29a2df8b55496890e3f00418f64a97" + ); assert_eq!(utxo_tokens[6].id, 86923); - assert_eq!(utxo_tokens[6].fingerprint, "asset1lg82x7zq3c3fy7w29crkwmnfuv2hj03p2ygmc6"); + assert_eq!( + utxo_tokens[6].fingerprint, + "asset1lg82x7zq3c3fy7w29crkwmnfuv2hj03p2ygmc6" + ); assert_eq!(utxo_tokens[6].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[6].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[6].name.clone()), "966a2d0a8a6b14e67455f9cb3e4ac59cfa6c75b570ead071b1cf1a1472a549c4"); + assert_eq!( + hex::encode(utxo_tokens[6].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[6].name.clone()), + "966a2d0a8a6b14e67455f9cb3e4ac59cfa6c75b570ead071b1cf1a1472a549c4" + ); assert_eq!(utxo_tokens[7].id, 86963); - assert_eq!(utxo_tokens[7].fingerprint, "asset16x02ett6wtfjkf4ayz2zfjgec2m6pyr6r6xrmr"); + assert_eq!( + utxo_tokens[7].fingerprint, + "asset16x02ett6wtfjkf4ayz2zfjgec2m6pyr6r6xrmr" + ); assert_eq!(utxo_tokens[7].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[7].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[7].name.clone()), "a2b7d3bd6c650fe388b67841d321d39bdcfcb42a7be15163d033f28a742ca9d6"); + assert_eq!( + hex::encode(utxo_tokens[7].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[7].name.clone()), + "a2b7d3bd6c650fe388b67841d321d39bdcfcb42a7be15163d033f28a742ca9d6" + ); assert_eq!(utxo_tokens[8].id, 100979); - assert_eq!(utxo_tokens[8].fingerprint, "asset14e7yfrgurya54e9k83axv3hw3s0kxluz289juu"); + assert_eq!( + utxo_tokens[8].fingerprint, + "asset14e7yfrgurya54e9k83axv3hw3s0kxluz289juu" + ); assert_eq!(utxo_tokens[8].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[8].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[8].name.clone()), "d8ae43a1a2a0ab24709fb6fc497963dc30d8b1ee941fb774f1c8f05f98e6e556"); + assert_eq!( + hex::encode(utxo_tokens[8].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[8].name.clone()), + "d8ae43a1a2a0ab24709fb6fc497963dc30d8b1ee941fb774f1c8f05f98e6e556" + ); assert_eq!(utxo_tokens[9].id, 88257); - assert_eq!(utxo_tokens[9].fingerprint, "asset1g5ekxpjwnxu43qaejp3ml8hdfqa38ug7w4z6pw"); + assert_eq!( + utxo_tokens[9].fingerprint, + "asset1g5ekxpjwnxu43qaejp3ml8hdfqa38ug7w4z6pw" + ); assert_eq!(utxo_tokens[9].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[9].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[9].name.clone()), "e52c1140e73aaf9c96cfb6a5f8a40de63cf9c75f9f25ae8a9359df39e037566e"); + assert_eq!( + hex::encode(utxo_tokens[9].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[9].name.clone()), + "e52c1140e73aaf9c96cfb6a5f8a40de63cf9c75f9f25ae8a9359df39e037566e" + ); assert_eq!(utxo_tokens[10].id, 86920); - assert_eq!(utxo_tokens[10].fingerprint, "asset13a25l8trzvf3g2pa4lfpmzdtas6wyrn07rjr9q"); + assert_eq!( + utxo_tokens[10].fingerprint, + "asset13a25l8trzvf3g2pa4lfpmzdtas6wyrn07rjr9q" + ); assert_eq!(utxo_tokens[10].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[10].policy.clone()), "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d"); - assert_eq!(hex::encode(utxo_tokens[10].name.clone()), "f32ba079cfbc64e8119354e93f3ce804922b5499d4e8265e50bc4cf0f65fd490"); + assert_eq!( + hex::encode(utxo_tokens[10].policy.clone()), + "8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837d" + ); + assert_eq!( + hex::encode(utxo_tokens[10].name.clone()), + "f32ba079cfbc64e8119354e93f3ce804922b5499d4e8265e50bc4cf0f65fd490" + ); assert_eq!(utxo_tokens[11].id, 6425); - assert_eq!(utxo_tokens[11].fingerprint, "asset1qpcwhg7cvg7wr4m5xa3vd2s79lutkf044pmg4z"); + assert_eq!( + utxo_tokens[11].fingerprint, + "asset1qpcwhg7cvg7wr4m5xa3vd2s79lutkf044pmg4z" + ); assert_eq!(utxo_tokens[11].quantity, BigDecimal::from(199217790)); - assert_eq!(hex::encode(utxo_tokens[11].policy.clone()), "fdc6402cf6c5a22e389ebb3f813af09f3502377885c2046e98ce2c88"); + assert_eq!( + hex::encode(utxo_tokens[11].policy.clone()), + "fdc6402cf6c5a22e389ebb3f813af09f3502377885c2046e98ce2c88" + ); assert_eq!(hex::encode(utxo_tokens[11].name.clone()), "69555344"); } @@ -2122,52 +2225,83 @@ mod tests { db_path: dotenv::var("DBSYNC_DB_URL").unwrap(), })); - let utxo_tokens = super::get_utxo_tokens( - dp.provider(), - 3317731, - 0 - ).unwrap(); + let utxo_tokens = super::get_utxo_tokens(dp.provider(), 3317731, 0).unwrap(); assert_eq!(utxo_tokens[0].id, 25777); - assert_eq!(utxo_tokens[0].fingerprint, "asset1jr6nl54y3rvpqfpmpau95q9lvu59fwq4f9xf9a"); + assert_eq!( + utxo_tokens[0].fingerprint, + "asset1jr6nl54y3rvpqfpmpau95q9lvu59fwq4f9xf9a" + ); assert_eq!(utxo_tokens[0].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[0].policy.clone()), "314de5f1c06ca6261a9159bfba61cfba8f4fb3ff37a2d68ec1b54c8a"); - assert_eq!(hex::encode(utxo_tokens[0].name.clone()), "546573746e65744e4654202337"); + assert_eq!( + hex::encode(utxo_tokens[0].policy.clone()), + "314de5f1c06ca6261a9159bfba61cfba8f4fb3ff37a2d68ec1b54c8a" + ); + assert_eq!( + hex::encode(utxo_tokens[0].name.clone()), + "546573746e65744e4654202337" + ); assert_eq!(utxo_tokens[1].id, 391); - assert_eq!(utxo_tokens[1].fingerprint, "asset1m099azmatp3f3xehsu4sqvr45jzqafxmm0dra0"); + assert_eq!( + utxo_tokens[1].fingerprint, + "asset1m099azmatp3f3xehsu4sqvr45jzqafxmm0dra0" + ); assert_eq!(utxo_tokens[1].quantity, BigDecimal::from(150)); - assert_eq!(hex::encode(utxo_tokens[1].policy.clone()), "3f1d9bd2f8c3d7d8144b789433261370eaf25cdc83fe8a745ef880c1"); + assert_eq!( + hex::encode(utxo_tokens[1].policy.clone()), + "3f1d9bd2f8c3d7d8144b789433261370eaf25cdc83fe8a745ef880c1" + ); assert_eq!(hex::encode(utxo_tokens[1].name.clone()), "744452415341"); assert_eq!(utxo_tokens[2].id, 2746); - assert_eq!(utxo_tokens[2].fingerprint, "asset10q8zsrnx5plw0k2l2e8slcjf4htuvu42jxrgl8"); + assert_eq!( + utxo_tokens[2].fingerprint, + "asset10q8zsrnx5plw0k2l2e8slcjf4htuvu42jxrgl8" + ); assert_eq!(utxo_tokens[2].quantity, BigDecimal::from(50)); - assert_eq!(hex::encode(utxo_tokens[2].policy.clone()), "dfd18a815a25339777dcc80bce9c438ad632272d95f334a111711ac9"); + assert_eq!( + hex::encode(utxo_tokens[2].policy.clone()), + "dfd18a815a25339777dcc80bce9c438ad632272d95f334a111711ac9" + ); assert_eq!(hex::encode(utxo_tokens[2].name.clone()), "7441726b"); - let utxo_tokens = super::get_utxo_tokens( - dp.provider(), - 3317731, - 1 - ).unwrap(); + let utxo_tokens = super::get_utxo_tokens(dp.provider(), 3317731, 1).unwrap(); assert_eq!(utxo_tokens[0].id, 367); - assert_eq!(utxo_tokens[0].fingerprint, "asset1wn7x62hf07wp36u6nmux467nrsngrcvurwqvm2"); + assert_eq!( + utxo_tokens[0].fingerprint, + "asset1wn7x62hf07wp36u6nmux467nrsngrcvurwqvm2" + ); assert_eq!(utxo_tokens[0].quantity, BigDecimal::from(1)); - assert_eq!(hex::encode(utxo_tokens[0].policy.clone()), "55e9a9737f5ee3f3a04a80b5bc9419c87724187318bd7ac376141e10"); + assert_eq!( + hex::encode(utxo_tokens[0].policy.clone()), + "55e9a9737f5ee3f3a04a80b5bc9419c87724187318bd7ac376141e10" + ); assert_eq!(hex::encode(utxo_tokens[0].name.clone()), "74656e4e465435"); assert_eq!(utxo_tokens[1].id, 392); - assert_eq!(utxo_tokens[1].fingerprint, "asset1e83uya776dvqjauy270qnj03899hxxant6jp2g"); + assert_eq!( + utxo_tokens[1].fingerprint, + "asset1e83uya776dvqjauy270qnj03899hxxant6jp2g" + ); assert_eq!(utxo_tokens[1].quantity, BigDecimal::from(75)); - assert_eq!(hex::encode(utxo_tokens[1].policy.clone()), "c693a41d2b4f241c992b88c7238131d92202206ffc92f5eae090d0ee"); + assert_eq!( + hex::encode(utxo_tokens[1].policy.clone()), + "c693a41d2b4f241c992b88c7238131d92202206ffc92f5eae090d0ee" + ); assert_eq!(hex::encode(utxo_tokens[1].name.clone()), "7454657374"); assert_eq!(utxo_tokens[2].id, 2746); - assert_eq!(utxo_tokens[2].fingerprint, "asset10q8zsrnx5plw0k2l2e8slcjf4htuvu42jxrgl8"); + assert_eq!( + utxo_tokens[2].fingerprint, + "asset10q8zsrnx5plw0k2l2e8slcjf4htuvu42jxrgl8" + ); assert_eq!(utxo_tokens[2].quantity, BigDecimal::from(50)); - assert_eq!(hex::encode(utxo_tokens[2].policy.clone()), "dfd18a815a25339777dcc80bce9c438ad632272d95f334a111711ac9"); + assert_eq!( + hex::encode(utxo_tokens[2].policy.clone()), + "dfd18a815a25339777dcc80bce9c438ad632272d95f334a111711ac9" + ); assert_eq!(hex::encode(utxo_tokens[2].name.clone()), "7441726b"); } -} \ No newline at end of file +} diff --git a/src/grpc.rs b/src/grpc.rs index e65ef90..e468657 100644 --- a/src/grpc.rs +++ b/src/grpc.rs @@ -55,11 +55,7 @@ impl ChainFollowerRequestService for AyaCardanoRPCServer { new_slot: resp.new_slot, new_blockhash: resp.new_blockhash, epoch_nonce: resp.epoch_nonce, - extra_entropy: if let Some(s) = resp.extra_entropy { - s - } else { - "".to_string() - }, + extra_entropy: resp.extra_entropy.unwrap_or_default(), })), } } diff --git a/src/provider/error.rs b/src/provider/error.rs index 1c5994a..705cc41 100644 --- a/src/provider/error.rs +++ b/src/provider/error.rs @@ -1,4 +1,5 @@ use thiserror::Error; +use warp::reject; #[allow(clippy::enum_variant_names)] #[derive(Error, Debug)] @@ -21,6 +22,8 @@ pub enum DataProviderError { JSONError(#[from] serde_json::Error), #[error(transparent)] CSLCommonError(#[from] dcslc::error::CSLCommonError), + #[error(transparent)] + BlockFrostApiError(#[from] blockfrost::Error), } impl From for DataProviderError { @@ -40,3 +43,5 @@ impl From for DataProviderError { DataProviderError::Custom(err.to_string()) } } + +impl reject::Reject for DataProviderError {} diff --git a/src/server/auth.rs b/src/server/auth.rs index 334a0f5..fad38f6 100644 --- a/src/server/auth.rs +++ b/src/server/auth.rs @@ -31,7 +31,7 @@ pub fn _create_jwt(uid: &str, role: &Role, expire: Option) -> Result Box { +fn get_cardano_data_provider() -> Result, DataProviderError> { let provider = std::env::var("PROVIDER").unwrap(); match provider.as_str() { - "blockfrost" => Box::new( - DataProvider::new( - BlockfrostProvider::new() - ) - ), - "dbsync" => Box::new( - DataProvider::new( - DBSyncProvider::new(crate::Config {db_path: std::env::var("DBSYNC_URL").unwrap()}) - ) - ), + "blockfrost" => { + let provider = Box::new(DataProvider::new(BlockfrostProvider::new()?)); + Ok(provider) + } + "dbsync" => { + let provider = Box::new(DataProvider::new(DBSyncProvider::new(crate::Config { + db_path: std::env::var("DBSYNC_URL").unwrap(), + }))); + Ok(provider) + } // Panic as we never should reach this, config is validated - _ => panic!("Provider #{provider} not recognised") + _ => unreachable!("Provider #{provider} not recognised"), } } @@ -46,7 +47,7 @@ pub async fn address_exists( let mut addresses: Vec = parse_string_vec_from_query(&addresses).unwrap(); let addresses = addresses.iter_mut().map(|address| &address[..]).collect(); - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let result = dp.addresses_exist(&addresses).await.unwrap(); Ok(rweb::Json::from(json!(result))) @@ -62,12 +63,12 @@ pub async fn utxos_per_addr( address: String, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let utxos = dp .script_utxos(&address) .await - .map_err(|e| RESTError::Custom(format!("Could not find UTxOs: {:?}",e)))?; + .map_err(|e| RESTError::Custom(format!("Could not find UTxOs: {:?}", e)))?; let result = serde_json::to_value(utxos.to_hex().unwrap()) .map_err(|_| RESTError::Custom("db error, could not get utxos".to_string()))?; @@ -99,8 +100,7 @@ pub async fn mint_metadata( fingerprint: String, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let metadata: TokenInfoView = match dp.mint_metadata(&fingerprint).await { Ok(metadata) => metadata, @@ -139,7 +139,7 @@ pub async fn tx_history( #[query] slot: String, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let mut addresses: Vec = parse_string_vec_from_query(&addresses).unwrap(); let addresses = addresses.iter_mut().map(|address| &address[..]).collect(); @@ -213,7 +213,7 @@ pub(crate) async fn get_asset_for_addresses( addresses: &Vec, ) -> Result, Rejection> { debug!("{addresses:?}"); - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let mut utxos = TransactionUnspentOutputs::new(); @@ -425,7 +425,7 @@ pub async fn retrieve_active_pools( page: usize, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let pools_page = dp.active_pools(page).await.unwrap(); Ok(rweb::Json::from(json!(pools_page))) } @@ -464,7 +464,6 @@ pub async fn is_nft( #[query] fingerprints: String, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - // Return if provider is blockfrost, BF does not support fingerprint-based requests let provider = std::env::var("PROVIDER").unwrap(); if provider.as_str() == "blockfrost" { @@ -517,7 +516,7 @@ pub async fn retrieve_staked_amount( stake_addr: String, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; dbg!(epoch.clone()); dbg!(stake_addr.clone()); @@ -541,7 +540,7 @@ pub async fn retrieve_generated_rewards( stake_addr: String, #[filter = "with_auth"] _user_id: String, ) -> Result, Rejection> { - let dp = get_cardano_data_provider(); + let dp = get_cardano_data_provider()?; let generated_rewards = dp .retrieve_generated_rewards(&stake_addr)