From cc4e15e8f2577071ba6db03623d22e53295f9b56 Mon Sep 17 00:00:00 2001
From: Patrice Tisserand
Date: Mon, 22 Apr 2024 13:54:28 +0200
Subject: [PATCH] cargo fmt
---
apps/indexer/refund/src/bin/extract_refund.rs | 38 +++++++++++++------
apps/indexer/refund/src/lib.rs | 2 +-
2 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/apps/indexer/refund/src/bin/extract_refund.rs b/apps/indexer/refund/src/bin/extract_refund.rs
index 0d448b45..1e851813 100644
--- a/apps/indexer/refund/src/bin/extract_refund.rs
+++ b/apps/indexer/refund/src/bin/extract_refund.rs
@@ -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")]
@@ -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 {
- 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::() {
Ok(p) => Ok(p),
- Err(e) => Err(anyhow!("Failed to parse STRK price: {:?}", e))
+ Err(e) => Err(anyhow!("Failed to parse STRK price: {:?}", e)),
}
}
@@ -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() {
@@ -79,7 +92,8 @@ async fn main() -> Result<()> {
};
if refund != "-1" {
let amount_usd = refund.parse::().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,
@@ -95,4 +109,4 @@ async fn main() -> Result<()> {
}
wtr.flush()?;
Ok(())
-}
\ No newline at end of file
+}
diff --git a/apps/indexer/refund/src/lib.rs b/apps/indexer/refund/src/lib.rs
index 73fc5212..2a582667 100644
--- a/apps/indexer/refund/src/lib.rs
+++ b/apps/indexer/refund/src/lib.rs
@@ -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,
}