Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ptisserand committed Apr 22, 2024
1 parent 7e0c5d9 commit cc4e15e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions apps/indexer/refund/src/bin/extract_refund.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@

use anyhow::{anyhow, Result};
use clap::Parser;

use starklane_indexer::{price::moralis::MoralisPrice, storage::{extract_database_name, mongo::MongoStore, store::{EventStore, RequestStore}}};
use starklane_indexer::{
price::moralis::MoralisPrice,
storage::{
extract_database_name,
mongo::MongoStore,
store::{EventStore, RequestStore},
},
};

use refund::Refund;

const ENV_PREFIX: &'static str = "INDEXER";
const ENV_SEPARATOR: &'static str = "__"; // "_" can't be used since we have key with '_' in json

const ENV_PREFIX: &str = "INDEXER";
const ENV_SEPARATOR: &str = "__"; // "_" can't be used since we have key with '_' in json

#[derive(Parser, Debug)]
#[clap(about = "Extract refund")]
Expand All @@ -23,17 +28,19 @@ struct Args {
output: String,

#[clap(long, help = "Ceil amount (false by default)", default_value_t = false)]
ceil: bool
ceil: bool,
}

const STRK_ADDR_ETH: &str = "0xCa14007Eff0dB1f8135f4C25B34De49AB0d42766";
const STRK_ADDR_STRK: &str = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";

async fn get_strk_price() -> Result<f64> {
let price = MoralisPrice::new(None).get_price(STRK_ADDR_ETH, None).await?;
let price = MoralisPrice::new(None)
.get_price(STRK_ADDR_ETH, None)
.await?;
match price.parse::<f64>() {
Ok(p) => Ok(p),
Err(e) => Err(anyhow!("Failed to parse STRK price: {:?}", e))
Err(e) => Err(anyhow!("Failed to parse STRK price: {:?}", e)),
}
}

Expand Down Expand Up @@ -64,10 +71,16 @@ async fn main() -> Result<()> {
let dbname = extract_database_name(&args.mongodb)
.expect("Database name couldn't be extracted from the connection string");
let mongo_store = MongoStore::new(&args.mongodb, dbname).await?;

let mut wtr = csv::Writer::from_path(output)?;

if let Ok(events) = mongo_store.events_by_label(starklane_indexer::storage::EventLabel::DepositInitiatedL1, true).await {
if let Ok(events) = mongo_store
.events_by_label(
starklane_indexer::storage::EventLabel::DepositInitiatedL1,
true,
)
.await
{
for event in events {
let req = mongo_store.req_by_hash(&event.req_hash).await?;
if req.is_some() {
Expand All @@ -79,7 +92,8 @@ async fn main() -> Result<()> {
};
if refund != "-1" {
let amount_usd = refund.parse::<f64>().unwrap();
let amount = compute_amount_strk(amount_usd, strk_price, amount_max as f64, args.ceil);
let amount =
compute_amount_strk(amount_usd, strk_price, amount_max as f64, args.ceil);
let refund_info = Refund {
token_address: STRK_ADDR_STRK.to_owned(),
dest: req.to,
Expand All @@ -95,4 +109,4 @@ async fn main() -> Result<()> {
}
wtr.flush()?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion apps/indexer/refund/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub struct Refund {
#[serde(rename = "USD")]
pub amount_usd: f64,
#[serde(rename = "Transaction Hash")]
pub tx_hash: String
pub tx_hash: String,
}

0 comments on commit cc4e15e

Please sign in to comment.