diff --git a/src/blockfrost/api.rs b/src/blockfrost/api.rs index d6e8d1f..26087f8 100644 --- a/src/blockfrost/api.rs +++ b/src/blockfrost/api.rs @@ -4,7 +4,7 @@ use super::error::DataProviderBlockfrostError; use super::BlockfrostProvider; use crate::models::{ CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, StakeDelegationView, - StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, + StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, PoolInfo }; use crate::provider::error::DataProviderError; use blockfrost::{AccountAddress, AddressUtxo}; @@ -258,14 +258,15 @@ pub fn retrieve_generated_rewards ( Ok(vec![]) } - +#[cfg(feature = "granular_pool")] pub fn pool_vrf_key_hash ( bfp: &BlockfrostProvider, pool_hash: &str, -) -> Result, DataProviderError> { +) -> Result { todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_blocks_minted ( bfp: &BlockfrostProvider, pool_hash: &str, @@ -273,6 +274,7 @@ pub fn pool_blocks_minted ( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_blocks_current_epoch( bfp: &BlockfrostProvider, pool_hash: &str, @@ -280,6 +282,7 @@ pub fn pool_blocks_current_epoch( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_reward_recipients( bfp: &BlockfrostProvider, pool_hash: &str, @@ -287,6 +290,7 @@ pub fn pool_reward_recipients( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_last_reward_earned_epoch( bfp: &BlockfrostProvider, pool_hash: &str, @@ -294,6 +298,7 @@ pub fn pool_last_reward_earned_epoch( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_declared_pledge( bfp: &BlockfrostProvider, pool_hash: &str, @@ -301,6 +306,7 @@ pub fn pool_declared_pledge( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_margin_cost( bfp: &BlockfrostProvider, pool_hash: &str, @@ -308,6 +314,7 @@ pub fn pool_margin_cost( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_fixed_cost( bfp: &BlockfrostProvider, pool_hash: &str, @@ -315,6 +322,7 @@ pub fn pool_fixed_cost( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_reward_address( bfp: &BlockfrostProvider, pool_hash: &str, @@ -322,6 +330,7 @@ pub fn pool_reward_address( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_owner( bfp: &BlockfrostProvider, pool_hash: &str, @@ -329,6 +338,7 @@ pub fn pool_owner( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_registration( bfp: &BlockfrostProvider, pool_hash: &str, @@ -336,6 +346,7 @@ pub fn pool_registration( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_retirement( bfp: &BlockfrostProvider, pool_hash: &str, @@ -343,6 +354,7 @@ pub fn pool_retirement( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_url( bfp: &BlockfrostProvider, pool_hash: &str, @@ -350,6 +362,7 @@ pub fn pool_url( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_ticker( bfp: &BlockfrostProvider, pool_hash: &str, @@ -357,6 +370,7 @@ pub fn pool_ticker( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_metadata_json( bfp: &BlockfrostProvider, pool_hash: &str, @@ -364,6 +378,7 @@ pub fn pool_metadata_json( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_name( bfp: &BlockfrostProvider, pool_hash: &str, @@ -371,6 +386,7 @@ pub fn pool_name( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_homepage( bfp: &BlockfrostProvider, pool_hash: &str, @@ -378,9 +394,17 @@ pub fn pool_homepage( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_description( bfp: &BlockfrostProvider, pool_hash: &str, ) -> Result { todo!() +} + +pub fn pool_info( + bfp: &BlockfrostProvider, + pool_hash: &str, +) -> Result { + todo!() } \ No newline at end of file diff --git a/src/blockfrost/mod.rs b/src/blockfrost/mod.rs index 8377c56..bb63c30 100644 --- a/src/blockfrost/mod.rs +++ b/src/blockfrost/mod.rs @@ -1,6 +1,6 @@ use crate::provider::error::DataProviderError; use crate::models::{CDPDatum, RewardView, TokenInfoView, CardanoNativeAssetView, StakeDelegationView, DelegationView, - StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView + StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView, PoolInfo }; use async_trait::async_trait; @@ -269,13 +269,15 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::retrieve_generated_rewards(self, stake_addr)?) } + #[cfg(feature = "granular_pool")] async fn pool_vrf_key_hash ( &self, pool_hash: &str, - ) -> Result, DataProviderError> { + ) -> Result { Ok(api::pool_vrf_key_hash(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_minted ( &self, pool_hash: &str, @@ -283,6 +285,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_blocks_minted(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_current_epoch( &self, pool_hash: &str, @@ -290,6 +293,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_blocks_current_epoch(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_recipients( &self, pool_hash: &str, @@ -297,6 +301,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_reward_recipients(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_last_reward_earned_epoch( &self, pool_hash: &str, @@ -304,6 +309,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_last_reward_earned_epoch(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_declared_pledge( &self, pool_hash: &str, @@ -311,6 +317,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_declared_pledge(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_margin_cost( &self, pool_hash: &str, @@ -318,6 +325,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_margin_cost(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_fixed_cost( &self, pool_hash: &str, @@ -325,6 +333,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_fixed_cost(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_address( &self, pool_hash: &str, @@ -332,6 +341,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_reward_address(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_owner( &self, pool_hash: &str, @@ -339,6 +349,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_owner(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_registration( &self, pool_hash: &str, @@ -346,6 +357,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_registration(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_retirement( &self, pool_hash: &str, @@ -353,6 +365,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_retirement(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_url( &self, pool_hash: &str, @@ -360,6 +373,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_url(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_ticker( &self, pool_hash: &str, @@ -367,6 +381,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_ticker(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_metadata_json( &self, pool_hash: &str, @@ -374,6 +389,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_metadata_json(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_name( &self, pool_hash: &str, @@ -381,6 +397,7 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_name(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_homepage( &self, pool_hash: &str, @@ -388,10 +405,18 @@ impl super::provider::CardanoDataProvider for BlockfrostProvider { Ok(api::pool_homepage(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_description( &self, pool_hash: &str, ) -> Result { Ok(api::pool_description(self, pool_hash)?) } + + async fn pool_info( + &self, + pool_hash: &str, + ) -> Result { + Ok(api::pool_info(self, pool_hash)?) + } } diff --git a/src/carb/api.rs b/src/carb/api.rs index 3c526b0..8bd7707 100644 --- a/src/carb/api.rs +++ b/src/carb/api.rs @@ -2,7 +2,7 @@ use super::error::DataProviderCarbError; use super::CarbProvider; use crate::models::{ CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, StakeDelegationView, - StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, + StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, PoolInfo, }; use crate::provider::error::DataProviderError; @@ -200,13 +200,15 @@ pub fn retrieve_generated_rewards ( Ok(vec![]) } +#[cfg(feature = "granular_pool")] pub fn pool_vrf_key_hash ( bfp: &CarbProvider, pool_hash: &str, -) -> Result, DataProviderError> { +) -> Result { todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_blocks_minted ( bfp: &CarbProvider, pool_hash: &str, @@ -214,6 +216,7 @@ pub fn pool_blocks_minted ( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_blocks_current_epoch( bfp: &CarbProvider, pool_hash: &str, @@ -221,6 +224,7 @@ pub fn pool_blocks_current_epoch( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_reward_recipients( bfp: &CarbProvider, pool_hash: &str, @@ -228,6 +232,7 @@ pub fn pool_reward_recipients( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_last_reward_earned_epoch( bfp: &CarbProvider, pool_hash: &str, @@ -235,6 +240,7 @@ pub fn pool_last_reward_earned_epoch( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_declared_pledge( bfp: &CarbProvider, pool_hash: &str, @@ -242,6 +248,7 @@ pub fn pool_declared_pledge( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_margin_cost ( bfp: &CarbProvider, pool_hash: &str, @@ -249,6 +256,7 @@ pub fn pool_margin_cost ( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_fixed_cost( bfp: &CarbProvider, pool_hash: &str, @@ -256,6 +264,7 @@ pub fn pool_fixed_cost( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_reward_address( bfp: &CarbProvider, pool_hash: &str, @@ -263,6 +272,7 @@ pub fn pool_reward_address( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_owner( bfp: &CarbProvider, pool_hash: &str, @@ -270,6 +280,7 @@ pub fn pool_owner( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_registration( bfp: &CarbProvider, pool_hash: &str, @@ -277,6 +288,7 @@ pub fn pool_registration( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_retirement( bfp: &CarbProvider, pool_hash: &str, @@ -284,6 +296,7 @@ pub fn pool_retirement( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_url( bfp: &CarbProvider, pool_hash: &str, @@ -291,6 +304,7 @@ pub fn pool_url( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_ticker( bfp: &CarbProvider, pool_hash: &str, @@ -298,6 +312,7 @@ pub fn pool_ticker( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_metadata_json( bfp: &CarbProvider, pool_hash: &str, @@ -305,6 +320,7 @@ pub fn pool_metadata_json( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_name( bfp: &CarbProvider, pool_hash: &str, @@ -312,6 +328,7 @@ pub fn pool_name( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_homepage( bfp: &CarbProvider, pool_hash: &str, @@ -319,9 +336,17 @@ pub fn pool_homepage( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_description( bfp: &CarbProvider, pool_hash: &str, ) -> Result { todo!() +} + +pub fn pool_info( + bfp: &CarbProvider, + pool_hash: &str, +) -> Result { + todo!() } \ No newline at end of file diff --git a/src/carb/mod.rs b/src/carb/mod.rs index eb07b7d..50b859c 100644 --- a/src/carb/mod.rs +++ b/src/carb/mod.rs @@ -1,5 +1,6 @@ use crate::models::{CDPDatum, RewardView, TokenInfoView, CardanoNativeAssetView, StakeDelegationView, - DelegationView, StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView + DelegationView, StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView, + PoolInfo }; use crate::provider::error::DataProviderError; @@ -257,13 +258,15 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::retrieve_generated_rewards(self, stake_addr)?) } + #[cfg(feature = "granular_pool")] async fn pool_vrf_key_hash ( &self, pool_hash: &str, - ) -> Result, DataProviderError> { + ) -> Result { Ok(api::pool_vrf_key_hash(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_minted ( &self, pool_hash: &str, @@ -271,6 +274,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_blocks_minted(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_current_epoch( &self, pool_hash: &str, @@ -278,6 +282,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_blocks_current_epoch(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_recipients( &self, pool_hash: &str, @@ -285,6 +290,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_reward_recipients(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_last_reward_earned_epoch( &self, pool_hash: &str, @@ -292,6 +298,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_last_reward_earned_epoch(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_declared_pledge( &self, pool_hash: &str, @@ -299,6 +306,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_declared_pledge(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_margin_cost( &self, pool_hash: &str, @@ -306,6 +314,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_margin_cost(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_fixed_cost( &self, pool_hash: &str, @@ -313,6 +322,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_fixed_cost(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_address( &self, pool_hash: &str, @@ -320,6 +330,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_reward_address(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_owner( &self, pool_hash: &str, @@ -327,6 +338,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_owner(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_registration( &self, pool_hash: &str, @@ -334,6 +346,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_registration(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_retirement( &self, pool_hash: &str, @@ -341,7 +354,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_retirement(self, pool_hash)?) } - + #[cfg(feature = "granular_pool")] async fn pool_url( &self, pool_hash: &str, @@ -349,6 +362,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_url(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_ticker( &self, pool_hash: &str, @@ -356,6 +370,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_ticker(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_metadata_json( &self, pool_hash: &str, @@ -363,6 +378,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_metadata_json(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_name( &self, pool_hash: &str, @@ -370,6 +386,7 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_name(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_homepage( &self, pool_hash: &str, @@ -377,10 +394,18 @@ impl super::provider::CardanoDataProvider for CarbProvider { Ok(api::pool_homepage(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_description( &self, pool_hash: &str, ) -> Result { Ok(api::pool_description(self, pool_hash)?) } + + async fn pool_info( + &self, + pool_hash: &str, + ) -> Result { + Ok(api::pool_info(self, pool_hash)?) + } } diff --git a/src/dbsync/api.rs b/src/dbsync/api.rs index c070ee7..983087f 100644 --- a/src/dbsync/api.rs +++ b/src/dbsync/api.rs @@ -6,7 +6,7 @@ use crate::models::{ CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, PoolView, RewardView, ScriptView, StakeDelegationView, StakeDeregistrationView, StakeRegistrationView, TokenInfoView, TransactionView, TxHistoryListQuery, TxHistoryListQueryLight, TxHistoryListView, UTxOView, - WithdrawalView, + WithdrawalView, PoolInfo }; use crate::DBSyncProvider; use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; @@ -1837,15 +1837,18 @@ pub async fn epoch_change( pub async fn pool_vrf_key_hash( dbs: &DBSyncProvider, pool_hash: &str, -) -> Result, DataProviderDBSyncError> { - Ok( +) -> Result { + let bytes = pool_update::table .inner_join(pool_hash::table.on(pool_hash::id.eq(pool_update::hash_id))) .filter(pool_hash::view.eq(pool_hash.to_string())) .order(pool_update::active_epoch_no.desc()) .select(pool_update::vrf_key_hash) - .first::>(&mut dbs.connect()?)? - ) + .first::>(&mut dbs.connect()?)?; + + let hex = hex::encode(bytes); + + Ok(hex) } /// Total number of blocks ever minted by the given stake pool. @@ -2145,6 +2148,33 @@ pub async fn pool_description( ) } +/// All information about a given stakepool +pub async fn pool_info( + dbs: &DBSyncProvider, + pool_hash: &str, +) -> Result { + let r = PoolInfo { + vrf_key_hash: pool_vrf_key_hash(dbs, pool_hash).await.ok(), + blocks_minted: pool_blocks_minted(dbs, pool_hash).await.ok(), + blocks_current_epoch: pool_blocks_current_epoch(dbs, pool_hash).await.ok(), + reward_recipients: pool_reward_recipients(dbs, pool_hash).await.ok(), + last_reward_earned_epoch: pool_last_reward_earned_epoch(dbs, pool_hash).await.ok(), + declared_pledge: pool_declared_pledge(dbs, pool_hash).await.ok(), + margin_cost: pool_margin_cost(dbs, pool_hash).await.ok(), + fixed_cost: pool_fixed_cost(dbs, pool_hash).await.ok(), + owner: pool_owner(dbs, pool_hash).await.ok(), + registration: pool_registration(dbs, pool_hash).await.ok(), + retirement: pool_retirement(dbs, pool_hash).await.ok(), + url: pool_url(dbs, pool_hash).await.ok(), + ticker: pool_ticker(dbs, pool_hash).await.ok(), + name: pool_name(dbs, pool_hash).await.ok(), + homepage: pool_homepage(dbs, pool_hash).await.ok(), + description: pool_description(dbs, pool_hash).await.ok() + }; + + Ok(r) +} + #[cfg(test)] mod tests { use crate::{dbsync::DataProviderDBSyncError, provider::CardanoDataProvider}; diff --git a/src/dbsync/mod.rs b/src/dbsync/mod.rs index c98db9a..e404566 100644 --- a/src/dbsync/mod.rs +++ b/src/dbsync/mod.rs @@ -12,8 +12,8 @@ use bigdecimal::BigDecimal; use serde_json::Value; use crate::models::{CDPDatum, RewardView, TokenInfoView, CardanoNativeAssetView, StakeDelegationView, - DelegationView, StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, - TxHistoryListView + DelegationView, StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, + TxHistoryListView, PoolInfo }; use crate::provider::error::DataProviderError; @@ -265,13 +265,15 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::retrieve_generated_rewards(self, stake_addr)?) } + #[cfg(feature = "granular_pool")] async fn pool_vrf_key_hash ( &self, pool_hash: &str, - ) -> Result, DataProviderError> { + ) -> Result { Ok(api::pool_vrf_key_hash(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_minted ( &self, pool_hash: &str, @@ -279,6 +281,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_blocks_minted(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_current_epoch( &self, pool_hash: &str, @@ -286,6 +289,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_blocks_current_epoch(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_recipients( &self, pool_hash: &str, @@ -293,6 +297,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_reward_recipients(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_last_reward_earned_epoch( &self, pool_hash: &str, @@ -300,6 +305,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_last_reward_earned_epoch(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_declared_pledge( &self, pool_hash: &str, @@ -307,6 +313,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_declared_pledge(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_margin_cost( &self, pool_hash: &str, @@ -314,6 +321,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_margin_cost(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_fixed_cost( &self, pool_hash: &str, @@ -321,6 +329,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_fixed_cost(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_address( &self, pool_hash: &str, @@ -328,6 +337,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_reward_address(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_owner( &self, pool_hash: &str, @@ -335,6 +345,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_owner(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_registration( &self, pool_hash: &str, @@ -342,6 +353,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_registration(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_retirement( &self, pool_hash: &str, @@ -349,6 +361,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_retirement(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_url( &self, pool_hash: &str, @@ -356,6 +369,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_url(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_ticker( &self, pool_hash: &str, @@ -363,6 +377,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_ticker(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_metadata_json( &self, pool_hash: &str, @@ -370,6 +385,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_metadata_json(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_name( &self, pool_hash: &str, @@ -377,6 +393,7 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_name(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_homepage( &self, pool_hash: &str, @@ -384,10 +401,18 @@ impl super::provider::CardanoDataProvider for DBSyncProvider { Ok(api::pool_homepage(self, pool_hash).await?) } + #[cfg(feature = "granular_pool")] async fn pool_description( &self, pool_hash: &str, ) -> Result { Ok(api::pool_description(self, pool_hash).await?) } + + async fn pool_info( + &self, + pool_hash: &str, + ) -> Result { + Ok(api::pool_info(self, pool_hash).await?) + } } diff --git a/src/dbsync/models.rs b/src/dbsync/models.rs index f96a475..618399e 100644 --- a/src/dbsync/models.rs +++ b/src/dbsync/models.rs @@ -887,4 +887,4 @@ pub struct Withdrawal { pub amount: BigDecimal, pub redeemer_id: Option, pub tx_id: i64, -} +} \ No newline at end of file diff --git a/src/koios/api.rs b/src/koios/api.rs index 114aa01..237c0a3 100644 --- a/src/koios/api.rs +++ b/src/koios/api.rs @@ -2,7 +2,7 @@ use super::error::DataProviderKoiosError; use super::KoiosProvider; use crate::models::{ CDPDatum, CardanoNativeAssetView, DelegationView, HoldingWalletView, StakeDelegationView, - StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, + StakeDeregistrationView, StakeRegistrationView, TokenInfoView, RewardView, PoolInfo }; use bigdecimal::BigDecimal; use serde_json::{Value, json}; @@ -202,13 +202,15 @@ pub fn retrieve_generated_rewards ( Ok(vec![]) } +#[cfg(feature = "granular_pool")] pub fn pool_vrf_key_hash( bfp: &KoiosProvider, pool_hash: &str, -) -> Result, DataProviderKoiosError> { +) -> Result { todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_blocks_minted( bfp: &KoiosProvider, pool_hash: &str, @@ -216,6 +218,7 @@ pub fn pool_blocks_minted( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_blocks_current_epoch( bfp: &KoiosProvider, pool_hash: &str, @@ -223,6 +226,7 @@ pub fn pool_blocks_current_epoch( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_reward_recipients( bfp: &KoiosProvider, pool_hash: &str, @@ -230,6 +234,7 @@ pub fn pool_reward_recipients( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_last_reward_earned_epoch( bfp: &KoiosProvider, pool_hash: &str, @@ -237,6 +242,7 @@ pub fn pool_last_reward_earned_epoch( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_declared_pledge( bfp: &KoiosProvider, pool_hash: &str, @@ -244,6 +250,7 @@ pub fn pool_declared_pledge( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_margin_cost( bfp: &KoiosProvider, pool_hash: &str, @@ -251,6 +258,7 @@ pub fn pool_margin_cost( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_fixed_cost( bfp: &KoiosProvider, pool_hash: &str, @@ -258,6 +266,7 @@ pub fn pool_fixed_cost( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_reward_address( bfp: &KoiosProvider, pool_hash: &str, @@ -265,6 +274,7 @@ pub fn pool_reward_address( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_owner( bfp: &KoiosProvider, pool_hash: &str, @@ -272,6 +282,7 @@ pub fn pool_owner( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_registration( bfp: &KoiosProvider, pool_hash: &str, @@ -279,6 +290,7 @@ pub fn pool_registration( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_retirement( bfp: &KoiosProvider, pool_hash: &str, @@ -286,6 +298,7 @@ pub fn pool_retirement( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_url( bfp: &KoiosProvider, pool_hash: &str, @@ -293,6 +306,7 @@ pub fn pool_url( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_ticker( bfp: &KoiosProvider, pool_hash: &str, @@ -300,6 +314,7 @@ pub fn pool_ticker( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_metadata_json( bfp: &KoiosProvider, pool_hash: &str, @@ -307,6 +322,7 @@ pub fn pool_metadata_json( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_name( bfp: &KoiosProvider, pool_hash: &str, @@ -314,6 +330,7 @@ pub fn pool_name( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_homepage( bfp: &KoiosProvider, pool_hash: &str, @@ -321,9 +338,17 @@ pub fn pool_homepage( todo!() } +#[cfg(feature = "granular_pool")] pub fn pool_description( bfp: &KoiosProvider, pool_hash: &str, ) -> Result { todo!() +} + +pub fn pool_info( + bfp: &KoiosProvider, + pool_hash: &str, +) -> Result { + todo!() } \ No newline at end of file diff --git a/src/koios/mod.rs b/src/koios/mod.rs index 80b672b..443ef87 100644 --- a/src/koios/mod.rs +++ b/src/koios/mod.rs @@ -1,5 +1,5 @@ use crate::models::{CDPDatum, TokenInfoView, CardanoNativeAssetView, StakeDelegationView, DelegationView, - StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView, RewardView + StakeRegistrationView, StakeDeregistrationView, HoldingWalletView, TxHistoryListView, RewardView, PoolInfo }; use crate::provider::error::DataProviderError; @@ -255,13 +255,15 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::retrieve_generated_rewards(self, stake_addr)?) } + #[cfg(feature = "granular_pool")] async fn pool_vrf_key_hash( &self, pool_hash: &str, - ) -> Result, DataProviderError> { + ) -> Result { Ok(api::pool_vrf_key_hash(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_minted( &self, pool_hash: &str, @@ -269,6 +271,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_blocks_minted(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_blocks_current_epoch( &self, pool_hash: &str, @@ -276,6 +279,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_blocks_current_epoch(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_recipients( &self, pool_hash: &str, @@ -283,6 +287,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_reward_recipients(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_last_reward_earned_epoch( &self, pool_hash: &str, @@ -290,6 +295,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_last_reward_earned_epoch(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_declared_pledge( &self, pool_hash: &str, @@ -297,6 +303,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_declared_pledge(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_margin_cost( &self, pool_hash: &str, @@ -304,6 +311,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_margin_cost(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_fixed_cost( &self, pool_hash: &str, @@ -311,6 +319,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_fixed_cost(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_reward_address( &self, pool_hash: &str, @@ -318,6 +327,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_reward_address(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_owner( &self, pool_hash: &str, @@ -325,6 +335,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_owner(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_registration( &self, pool_hash: &str, @@ -332,6 +343,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_registration(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_retirement( &self, pool_hash: &str, @@ -339,6 +351,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_retirement(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_url( &self, pool_hash: &str, @@ -346,6 +359,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_url(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_ticker( &self, pool_hash: &str, @@ -353,6 +367,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_ticker(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_metadata_json( &self, pool_hash: &str, @@ -360,6 +375,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_metadata_json(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_name( &self, pool_hash: &str, @@ -367,6 +383,7 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_name(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_homepage( &self, pool_hash: &str, @@ -374,10 +391,18 @@ impl super::provider::CardanoDataProvider for KoiosProvider { Ok(api::pool_homepage(self, pool_hash)?) } + #[cfg(feature = "granular_pool")] async fn pool_description( &self, pool_hash: &str, ) -> Result { Ok(api::pool_description(self, pool_hash)?) } + + async fn pool_info( + &self, + pool_hash: &str, + ) -> Result { + Ok(api::pool_info(self, pool_hash)?) + } } diff --git a/src/models.rs b/src/models.rs index 8ed2a9e..8505126 100644 --- a/src/models.rs +++ b/src/models.rs @@ -4,11 +4,13 @@ use bigdecimal::{BigDecimal, ToPrimitive}; use cardano_serialization_lib::{crypto::ScriptHash, utils::BigNum, AssetName}; use dcslc::{make_fingerprint, TransactionUnspentOutput}; use diesel::Queryable; +use serde::Serialize; +use serde::Deserialize; pub type Token = (ScriptHash, AssetName, BigNum); pub type Tokens = Vec; -#[derive(Queryable, serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Queryable, Serialize, Deserialize, Debug, Clone)] pub struct TokenInfoView { pub fingerprint: String, pub policy: String, @@ -20,13 +22,13 @@ pub struct TokenInfoView { pub txhash: Option, } -#[derive(Queryable, serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Queryable, Serialize, Deserialize, Debug, Clone)] pub struct StakeDelegationView { pub stake_address: String, pub amount: BigDecimal, } -#[derive(Queryable, serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Queryable, Serialize, Deserialize, Debug, Clone)] pub struct DelegationView { pub stake_address: String, pub amount: i64, @@ -34,7 +36,7 @@ pub struct DelegationView { pub active_epoch_no: i64, } -#[derive(Queryable, serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Queryable, Serialize, Deserialize, Debug, Clone)] pub struct HoldingWalletView { pub stake_address: String, pub amount: u64, @@ -43,7 +45,7 @@ pub struct HoldingWalletView { pub fingerprint: Option, } -#[derive(Queryable, serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Queryable, Serialize, Deserialize, Debug, Clone)] pub struct CardanoNativeAssetView { pub id: i64, pub policy: Vec, @@ -52,7 +54,7 @@ pub struct CardanoNativeAssetView { pub quantity: BigDecimal, } -#[derive(Queryable, Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Queryable, Debug, Clone, Serialize, Deserialize)] pub struct StakeDeregistrationView { pub stake_address: String, pub tx_hash: Vec, @@ -60,7 +62,7 @@ pub struct StakeDeregistrationView { pub epoch: i32, } -#[derive(Queryable, Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Queryable, Debug, Clone, Serialize, Deserialize)] pub struct StakeRegistrationView { pub stake_address: String, pub tx_hash: Vec, @@ -77,7 +79,7 @@ pub struct CDPDatum { pub addr_has_script: bool, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct TransactionView { pub hash: String, pub block: String, @@ -96,7 +98,7 @@ pub struct TransactionView { pub cbor: Option, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct TxHistoryListAssetView { fingerprint: String, amount: u64, @@ -117,7 +119,7 @@ impl TxHistoryListAssetView { } } -#[derive(serde::Serialize, serde::Deserialize, Debug, QueryableByName)] +#[derive(Serialize, Deserialize, Debug, QueryableByName)] pub struct TxHistoryListQuery { #[diesel(sql_type = diesel::sql_types::Bytea, column_name = hash, deserialize_as = Vec)] hash: Vec, @@ -129,7 +131,7 @@ pub struct TxHistoryListQuery { value: Vec, } -#[derive(serde::Serialize, serde::Deserialize, Debug, QueryableByName)] +#[derive(Serialize, Deserialize, Debug, QueryableByName)] pub struct TxHistoryListQueryLight { #[diesel(sql_type = diesel::sql_types::Bytea, column_name = hash, deserialize_as = Vec)] pub hash: Vec, @@ -137,13 +139,13 @@ pub struct TxHistoryListQueryLight { pub slot: i64, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct TxHistoryListViewLight { pub hash: Vec, pub slot: i64, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct TxHistoryListView { pub hash: String, pub slot: i64, @@ -169,13 +171,13 @@ impl TxHistoryListView { } } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct WithdrawalView { pub stake_address: String, pub amount: u64, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct ScriptView { pub hash: String, pub r#type: crate::dbsync::models::Scripttype, @@ -183,7 +185,7 @@ pub struct ScriptView { pub bytes: Option, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct UTxOView { pub hash: String, pub index: i32, @@ -229,13 +231,13 @@ impl UTxOView { } } } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct ValueView { pub coin: u64, pub multiasset: Option>, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct AssetHandle { pub fingerprint: Option, pub policy: Option, @@ -303,16 +305,36 @@ impl PartialEq for AssetHandle { } } -#[derive(Queryable, Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Queryable, Debug, Clone, Serialize, Deserialize)] pub struct PoolView { pub pool_hash: String, pub ticker: String, pub json: serde_json::Value, } -#[derive(Queryable, Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Queryable, Debug, Clone, Serialize, Deserialize)] pub struct RewardView { pub amount: u64, pub earned_epoch: i64, pub spendable_epoch: i64, } + +#[derive(Queryable, Debug, Serialize)] +pub struct PoolInfo { + pub vrf_key_hash: Option, + pub blocks_minted: Option, + pub blocks_current_epoch: Option, + pub reward_recipients: Option, + pub last_reward_earned_epoch: Option, + pub declared_pledge: Option, + pub margin_cost: Option, + pub fixed_cost: Option, + pub owner: Option, + pub registration: Option, + pub retirement: Option, + pub url: Option, + pub ticker: Option, + pub name: Option, + pub homepage: Option, + pub description: Option, +} \ No newline at end of file diff --git a/src/provider.rs b/src/provider.rs index 0eb8f7c..e5400f1 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -1,7 +1,6 @@ pub mod config; pub mod error; -use crate::models::{CDPDatum, TxHistoryListView -}; +use crate::models::{CDPDatum, TxHistoryListView, PoolInfo}; use super::models::{ CardanoNativeAssetView, DelegationView, HoldingWalletView, StakeDelegationView, @@ -135,95 +134,118 @@ pub trait CardanoDataProvider { stake_addr: &str, ) -> Result, DataProviderError>; + #[cfg(feature = "granular_pool")] async fn pool_vrf_key_hash( &self, pool_hash: &str, - ) -> Result, DataProviderError>; + ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_blocks_minted( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_blocks_current_epoch( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_reward_recipients( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_last_reward_earned_epoch( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_declared_pledge( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_margin_cost( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_fixed_cost( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_reward_address( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_owner( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_registration( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_retirement( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_url( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_ticker( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_metadata_json( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_name( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_homepage( &self, pool_hash: &str, ) -> Result; + #[cfg(feature = "granular_pool")] async fn pool_description( &self, pool_hash: &str, ) -> Result; + + async fn pool_info( + &self, + pool_hash: &str, + ) -> Result; } pub struct DataProvider { @@ -430,13 +452,15 @@ impl CardanoData dbg!(self.provider().retrieve_generated_rewards(stake_addr).await) } + #[cfg(feature = "granular_pool")] async fn pool_vrf_key_hash ( &self, pool_hash: &str, - ) -> Result, DataProviderError> { + ) -> Result { self.provider().pool_vrf_key_hash(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_blocks_minted ( &self, pool_hash: &str, @@ -444,6 +468,7 @@ impl CardanoData self.provider().pool_blocks_minted(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_blocks_current_epoch ( &self, pool_hash: &str, @@ -451,6 +476,7 @@ impl CardanoData self.provider().pool_blocks_current_epoch(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_reward_recipients ( &self, pool_hash: &str, @@ -458,6 +484,7 @@ impl CardanoData self.provider().pool_reward_recipients(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_last_reward_earned_epoch ( &self, pool_hash: &str, @@ -465,6 +492,7 @@ impl CardanoData self.provider().pool_last_reward_earned_epoch(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_declared_pledge ( &self, pool_hash: &str, @@ -472,6 +500,7 @@ impl CardanoData self.provider().pool_declared_pledge(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_margin_cost( &self, pool_hash: &str, @@ -479,6 +508,7 @@ impl CardanoData self.provider().pool_margin_cost(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_fixed_cost( &self, pool_hash: &str, @@ -486,6 +516,7 @@ impl CardanoData self.provider().pool_fixed_cost(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_reward_address( &self, pool_hash: &str, @@ -493,6 +524,7 @@ impl CardanoData self.provider().pool_reward_address(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_owner( &self, pool_hash: &str, @@ -500,6 +532,7 @@ impl CardanoData self.provider().pool_owner(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_registration( &self, pool_hash: &str, @@ -507,6 +540,7 @@ impl CardanoData self.provider().pool_registration(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_retirement( &self, pool_hash: &str, @@ -514,6 +548,7 @@ impl CardanoData self.provider().pool_retirement(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_url( &self, pool_hash: &str, @@ -521,6 +556,7 @@ impl CardanoData self.provider().pool_url(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_ticker( &self, pool_hash: &str, @@ -528,6 +564,7 @@ impl CardanoData self.provider().pool_ticker(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_metadata_json( &self, pool_hash: &str, @@ -535,6 +572,7 @@ impl CardanoData self.provider().pool_metadata_json(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_name( &self, pool_hash: &str, @@ -542,6 +580,7 @@ impl CardanoData self.provider().pool_name(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_homepage( &self, pool_hash: &str, @@ -549,10 +588,18 @@ impl CardanoData self.provider().pool_homepage(pool_hash).await } + #[cfg(feature = "granular_pool")] async fn pool_description( &self, pool_hash: &str, ) -> Result { self.provider().pool_description(pool_hash).await } + + async fn pool_info( + &self, + pool_hash: &str, + ) -> Result { + self.provider().pool_info(pool_hash).await + } } diff --git a/src/server/handler/handler_rest/info.rs b/src/server/handler/handler_rest/info.rs index 5eb5d5c..a65a16c 100644 --- a/src/server/handler/handler_rest/info.rs +++ b/src/server/handler/handler_rest/info.rs @@ -1,5 +1,6 @@ use std::str::from_utf8; +use crate::{DBSyncProvider, DataProvider}; use crate::dbsync::get_stake_address_utxos_dep; use crate::models::{AssetHandle, PoolView}; use crate::server::error::RESTError; @@ -12,6 +13,14 @@ use dcslc::{make_fingerprint, TransactionUnspentOutputs}; use rweb::*; use serde_json::json; +fn data_provider() -> Result, Rejection> { + let dp = DataProvider::new(DBSyncProvider::new(crate::Config { + db_path: std::env::var("DBSYNC_URL").map_err(|_| warp::reject::not_found())?, + })); + + Ok(dp) +} + #[get("/utxos/{address}")] #[openapi( id = "api.info.utxos", @@ -396,7 +405,7 @@ pub async fn handle_asset_for_stake_address( #[get("/pools/{page}")] #[openapi( id = "api.info.pools_one_page", - tags("Stake Pool"), + tags("Pool"), summary = "Get Stake Pool List (specified page)" )] pub async fn retrieve_active_pools( @@ -418,23 +427,6 @@ pub async fn retrieve_active_pools( Ok(rweb::Json::from(json!(pools_paged[page]))) } -#[get("/pools/pages")] -#[openapi( - id = "api.info.pools_all_pages", - tags("Stake Pool"), - summary = "Get Stake Pool List (all pages)" -)] -pub async fn retrieve_active_pools_all_pages( - #[filter = "with_auth"] _user_id: String, -) -> Result, Rejection> { - let dp = crate::DataProvider::new(crate::DBSyncProvider::new(crate::Config { - db_path: std::env::var("DBSYNC_URL").map_err(|_| warp::reject::not_found())?, - })); - let pools = crate::dbsync::get_pools(dp.provider()).await?; - let pools_paged: Vec> = pools.chunks(100).map(|s| s.into()).collect(); - Ok(rweb::Json::from(json!(pools_paged))) -} - #[get("/tokens/supply/{fingerprint}")] #[openapi( id = "api.info.tokens.supply", @@ -549,10 +541,11 @@ pub async fn retrieve_generated_rewards( Ok(rweb::Json::from(json!(generated_rewards))) } +#[cfg(feature = "granular_pool")] #[get("/pool/vrf_key_hash/{pool_hash}")] #[openapi( id = "api.info.pool.vrf_key_hash", - tags("Pool"), + tags("Pool Granular"), summary = "VRF key hash generated by the pool's VRF private key" )] pub async fn pool_vrf_key_hash( @@ -571,10 +564,11 @@ pub async fn pool_vrf_key_hash( Ok(rweb::Json::from(json!(pool_vrf_key_hash))) } +#[cfg(feature = "granular_pool")] #[get("/pool/blocks_minted/{pool_hash}")] #[openapi( id = "api.info.pool.blocks_minted", - tags("Pool"), + tags("Pool Granular"), summary = "Total number of blocks minted by the given pool" )] pub async fn pool_blocks_minted( @@ -593,10 +587,11 @@ pub async fn pool_blocks_minted( Ok(rweb::Json::from(json!(pool_blocks_minted))) } +#[cfg(feature = "granular_pool")] #[get("/pool/blocks_current_epoch/{pool_hash}")] #[openapi( id = "api.info.pool.blocks_current_epoch", - tags("Pool"), + tags("Pool Granular"), summary = "Quantity of blocks minted by the given pool in current epoch" )] pub async fn pool_blocks_current_epoch( @@ -615,10 +610,11 @@ pub async fn pool_blocks_current_epoch( Ok(rweb::Json::from(json!(pool_blocks_current_epoch))) } +#[cfg(feature = "granular_pool")] #[get("/pool/pool_reward_recipients/{pool_hash}")] #[openapi( id = "api.info.pool.pool_reward_recipients", - tags("Pool"), + tags("Pool Granular"), summary = "The quantity of delegators that received rewards last time (epoch) the given pool was a slot leader." )] pub async fn pool_reward_recipients( @@ -637,10 +633,11 @@ pub async fn pool_reward_recipients( Ok(rweb::Json::from(json!(pool_reward_recipients))) } +#[cfg(feature = "granular_pool")] #[get("/pool/last_reward_earned_epoch/{pool_hash}")] #[openapi( id = "api.info.pool.last_reward_earned_epoch", - tags("Pool"), + tags("Pool Granular"), summary = "The last epoch when the given pool gave rewards to delegators" )] pub async fn pool_last_reward_earned_epoch( @@ -659,11 +656,11 @@ pub async fn pool_last_reward_earned_epoch( Ok(rweb::Json::from(json!(pool_last_reward_earned_epoch))) } - +#[cfg(feature = "granular_pool")] #[get("/pool/declared_pledge/{pool_hash}")] #[openapi( id = "api.info.pool.declared_pledge", - tags("Pool"), + tags("Pool Granular"), summary = "The amount of Ada that the given stake pool has pledged to stake into their own pool" )] pub async fn pool_declared_pledge( @@ -682,10 +679,11 @@ pub async fn pool_declared_pledge( Ok(rweb::Json::from(json!(pool_declared_pledge))) } +#[cfg(feature = "granular_pool")] #[get("/pool/margin_cost/{pool_hash}")] #[openapi( id = "api.info.pool.margin_cost", - tags("Pool"), + tags("Pool Granular"), summary = "The percentage of delegator's stake rewards that pool owner receives as compensation for enabling delegators to delegate" )] pub async fn pool_margin_cost( @@ -704,10 +702,11 @@ pub async fn pool_margin_cost( Ok(rweb::Json::from(json!(pool_margin_cost))) } +#[cfg(feature = "granular_pool")] #[get("/pool/fixed_cost/{pool_hash}")] #[openapi( id = "api.info.pool.fixed_cost", - tags("Pool"), + tags("Pool Granular"), summary = "The fixed amount of Ada that the given stake pool receives every epoch from each delegator" )] pub async fn pool_fixed_cost( @@ -726,10 +725,11 @@ pub async fn pool_fixed_cost( Ok(rweb::Json::from(json!(pool_fixed_cost))) } +#[cfg(feature = "granular_pool")] #[get("/pool/reward_address/{pool_hash}")] #[openapi( id = "api.info.pool.reward_address", - tags("Pool"), + tags("Pool Granular"), summary = "The stake address to which the delegators pay the fixed cost and margin cost." )] pub async fn pool_reward_address( @@ -748,10 +748,11 @@ pub async fn pool_reward_address( Ok(rweb::Json::from(json!(pool_reward_address))) } +#[cfg(feature = "granular_pool")] #[get("/pool/owner/{pool_hash}")] #[openapi( id = "api.info.pool.owner", - tags("Pool"), + tags("Pool Granular"), summary = "The stake address that represents the owner of the given stake pool" )] pub async fn pool_owner( @@ -770,10 +771,11 @@ pub async fn pool_owner( Ok(rweb::Json::from(json!(pool_owner))) } +#[cfg(feature = "granular_pool")] #[get("/pool/registration/{pool_hash}")] #[openapi( id = "api.info.pool.registration", - tags("Pool"), + tags("Pool Granular"), summary = "The epoch in which the given stake pool made its latest registration." )] pub async fn pool_registration( @@ -792,10 +794,11 @@ pub async fn pool_registration( Ok(rweb::Json::from(json!(pool_registration))) } +#[cfg(feature = "granular_pool")] #[get("/pool/retirement/{pool_hash}")] #[openapi( id = "api.info.pool.retirement", - tags("Pool"), + tags("Pool Granular"), summary = "The epoch in which the given pool retired." )] pub async fn pool_retirement( @@ -814,10 +817,11 @@ pub async fn pool_retirement( Ok(rweb::Json::from(json!(pool_retirement))) } +#[cfg(feature = "granular_pool")] #[get("/pool/url/{pool_hash}")] #[openapi( id = "api.info.pool.url", - tags("Pool"), + tags("Pool Granular"), summary = "The url in which the given pool stores its metadata." )] pub async fn pool_url( @@ -836,10 +840,11 @@ pub async fn pool_url( Ok(rweb::Json::from(json!(pool_url))) } +#[cfg(feature = "granular_pool")] #[get("/pool/ticker/{pool_hash}")] #[openapi( id = "api.info.pool.ticker", - tags("Pool"), + tags("Pool Granular"), summary = "The ticker (abbreviated name) of the given stakepool." )] pub async fn pool_ticker( @@ -858,10 +863,11 @@ pub async fn pool_ticker( Ok(rweb::Json::from(json!(pool_ticker))) } +#[cfg(feature = "granular_pool")] #[get("/pool/metadata_json/{pool_hash}")] #[openapi( id = "api.info.pool.metadata_json", - tags("Pool"), + tags("Pool Granular"), summary = "Metadata, of the given stake pool, presented in JSON format" )] pub async fn pool_metadata_json( @@ -880,10 +886,11 @@ pub async fn pool_metadata_json( Ok(rweb::Json::from(pool_metadata_json)) } +#[cfg(feature = "granular_pool")] #[get("/pool/name/{pool_hash}")] #[openapi( id = "api.info.pool.name", - tags("Pool"), + tags("Pool Granular"), summary = "Name of the given stake pool" )] pub async fn pool_name( @@ -902,10 +909,11 @@ pub async fn pool_name( Ok(rweb::Json::from(json!(pool_name))) } +#[cfg(feature = "granular_pool")] #[get("/pool/homepage/{pool_hash}")] #[openapi( id = "api.info.pool.homepage", - tags("Pool"), + tags("Pool Granular"), summary = "Homepage of the given stake pool" )] pub async fn pool_homepage( @@ -924,10 +932,11 @@ pub async fn pool_homepage( Ok(rweb::Json::from(json!(pool_homepage))) } +#[cfg(feature = "granular_pool")] #[get("/pool/description/{pool_hash}")] #[openapi( id = "api.info.pool.description", - tags("Pool"), + tags("Pool Granular"), summary = "Description of the given stake pool" )] pub async fn pool_description( @@ -946,6 +955,24 @@ pub async fn pool_description( Ok(rweb::Json::from(json!(pool_description))) } +#[get("/pool/info/{pool_hash}")] +#[openapi( + id = "api.info.pool.info", + tags("Pool"), + summary = "All information about the given stake pool" +)] +pub async fn pool_info( + pool_hash: String, + #[filter = "with_auth"] _user_id: String, +) -> Result, Rejection> { + let pool_info = data_provider()? + .pool_info(&pool_hash) + .await + .map_err(|_| RESTError::Custom("Couldn't find all info of the given stake pool".to_string()))?; + + Ok(rweb::Json::from(json!(pool_info))) +} + #[cfg(test)] mod tests { diff --git a/src/server/handler/handler_rest/mod.rs b/src/server/handler/handler_rest/mod.rs index 53fc477..f03e6a7 100644 --- a/src/server/handler/handler_rest/mod.rs +++ b/src/server/handler/handler_rest/mod.rs @@ -3,8 +3,13 @@ pub(crate) mod info; use info::{ address_exists, handle_asset_for_stake_address, handle_get_asset_for_addresses, is_nft, - mint_metadata, retrieve_active_pools, retrieve_active_pools_all_pages, token_supply, tx_history, - tx_history_discover, utxos_per_addr, retrieve_staked_amount, retrieve_generated_rewards, pool_vrf_key_hash, + mint_metadata, retrieve_active_pools, token_supply, tx_history, + tx_history_discover, utxos_per_addr, retrieve_staked_amount, retrieve_generated_rewards, pool_info +}; + +#[cfg(feature = "granular_pool")] +use info::{ + pool_vrf_key_hash, pool_blocks_minted, pool_blocks_current_epoch, pool_reward_recipients, pool_last_reward_earned_epoch, pool_declared_pledge, pool_margin_cost, pool_fixed_cost, pool_reward_address, pool_owner, pool_registration, pool_retirement, pool_url, pool_ticker, pool_metadata_json, pool_name, @@ -25,29 +30,31 @@ use rweb::*; handle_asset_for_stake_address, handle_get_asset_for_addresses, retrieve_active_pools, - retrieve_active_pools_all_pages, is_nft, retrieve_staked_amount, retrieve_generated_rewards, - pool_vrf_key_hash, - pool_blocks_minted, - pool_blocks_current_epoch, - pool_reward_recipients, - pool_last_reward_earned_epoch, - pool_declared_pledge, - pool_margin_cost, - pool_fixed_cost, - pool_reward_address, - pool_owner, - pool_registration, - pool_retirement, - pool_url, - pool_ticker, - pool_metadata_json, - pool_name, - pool_homepage, - pool_description, + pool_info ) )] +#[cfg_attr(feature = "granular_pool", router( + pool_vrf_key_hash, + pool_blocks_minted, + pool_blocks_current_epoch, + pool_reward_recipients, + pool_last_reward_earned_epoch, + pool_declared_pledge, + pool_margin_cost, + pool_fixed_cost, + pool_reward_address, + pool_owner, + pool_registration, + pool_retirement, + pool_url, + pool_ticker, + pool_metadata_json, + pool_name, + pool_homepage, + pool_description, +))] #[openapi(id = "api.info", description = "Information Requests")] pub async fn info() {}