Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Aug 15, 2024
1 parent 6d5aa69 commit d382dc4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 14 deletions.
42 changes: 36 additions & 6 deletions lib/ain-ocean/src/api/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ use defichain_rpc::{
use super::AppContext;
use crate::Result;

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("gettoken{symbol}") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("gettoken{symbol}") }"#
)]
pub async fn get_token_cached(
ctx: &Arc<AppContext>,
symbol: &str,
Expand Down Expand Up @@ -46,7 +51,12 @@ pub async fn get_token_cached(
Ok(token)
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("listtoken") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("listtoken") }"#
)]
pub async fn list_token_cached(ctx: &Arc<AppContext>) -> Result<TokenResult> {
let tokens = ctx
.client
Expand All @@ -63,7 +73,12 @@ pub async fn list_token_cached(ctx: &Arc<AppContext>) -> Result<TokenResult> {
Ok(tokens)
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getpoolpair{id}") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getpoolpair{id}") }"#
)]
pub async fn get_pool_pair_cached(
ctx: &Arc<AppContext>,
id: String,
Expand Down Expand Up @@ -95,7 +110,12 @@ pub async fn get_pool_pair_cached(
Ok(pool_pair)
}

#[cached(result = true, time = 60, key = "String", convert = r#"{ format!("listpoolpairs") }"#)]
#[cached(
result = true,
time = 60,
key = "String",
convert = r#"{ format!("listpoolpairs") }"#
)]
pub async fn list_pool_pairs_cached(ctx: &Arc<AppContext>) -> Result<PoolPairsResult> {
let pool_pairs = ctx
.client
Expand All @@ -111,7 +131,12 @@ pub async fn list_pool_pairs_cached(ctx: &Arc<AppContext>) -> Result<PoolPairsRe
Ok(pool_pairs)
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getgov{id}") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getgov{id}") }"#
)]
pub async fn get_gov_cached(
ctx: &Arc<AppContext>,
id: String,
Expand All @@ -120,7 +145,12 @@ pub async fn get_gov_cached(
Ok(gov)
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getloanscheme{id}") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getloanscheme{id}") }"#
)]
pub async fn get_loan_scheme_cached(ctx: &Arc<AppContext>, id: String) -> Result<LoanSchemeResult> {
let loan_scheme = ctx.client.get_loan_scheme(id).await?;
Ok(loan_scheme)
Expand Down
56 changes: 48 additions & 8 deletions lib/ain-ocean/src/api/stats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ pub struct Burned {
pub total: Decimal,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getburned") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getburned") }"#
)]
pub async fn get_burned(client: &Client) -> Result<Burned> {
let burn_info = client.get_burn_info().await?;

Expand Down Expand Up @@ -71,7 +76,12 @@ pub struct Count {
pub masternodes: u32,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getcount") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getcount") }"#
)]
pub async fn get_count(ctx: &Arc<AppContext>) -> Result<Count> {
let tokens = ctx
.client
Expand Down Expand Up @@ -117,7 +127,12 @@ lazy_static::lazy_static! {
]);
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getburnedtotal") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getburnedtotal") }"#
)]
pub async fn get_burned_total(ctx: &AppContext) -> Result<Decimal> {
let burn_address = BURN_ADDRESS
.get(ctx.network.as_str())
Expand Down Expand Up @@ -161,7 +176,12 @@ pub struct Emission {
pub total: Decimal,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getemission") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getemission") }"#
)]
pub fn get_emission(height: u32) -> Result<Emission> {
let subsidy = Decimal::from_u64(BLOCK_SUBSIDY.get_block_subsidy(height))
.ok_or(Error::DecimalConversionError)?;
Expand Down Expand Up @@ -205,7 +225,12 @@ pub struct Loan {
pub value: LoanValue,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getloan") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getloan") }"#
)]
pub async fn get_loan(client: &Client) -> Result<Loan> {
let info = client.get_loan_info().await?;

Expand Down Expand Up @@ -236,7 +261,12 @@ pub struct Masternodes {
pub locked: Vec<Locked>,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getmasternodes") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getmasternodes") }"#
)]
pub async fn get_masternodes(ctx: &Arc<AppContext>) -> Result<Masternodes> {
let stats = ctx
.services
Expand Down Expand Up @@ -268,7 +298,12 @@ pub struct Tvl {
pub masternodes: Decimal,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("gettvl") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("gettvl") }"#
)]
pub async fn get_tvl(ctx: &Arc<AppContext>) -> Result<Tvl> {
// dex
let mut dex = dec!(0);
Expand Down Expand Up @@ -307,7 +342,12 @@ pub struct Price {
pub usdt: Decimal,
}

#[cached(result = true, time = 600, key = "String", convert = r#"{ format!("getprice") }"#)]
#[cached(
result = true,
time = 600,
key = "String",
convert = r#"{ format!("getprice") }"#
)]
pub async fn get_price(ctx: &Arc<AppContext>) -> Result<Price> {
let usd = get_usd_per_dfi(ctx).await?;
#[allow(deprecated)]
Expand Down

0 comments on commit d382dc4

Please sign in to comment.