Skip to content

Commit

Permalink
refactor: remove revert templates
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit committed Oct 23, 2023
1 parent 3f3a92e commit ffabbd4
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 519 deletions.
6 changes: 0 additions & 6 deletions ledger/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ pub(super) const DECREASE_EXCHANGE_POSITION_ID: Uuid =
uuid!("00000000-0000-0000-0000-000000000004");
pub(super) const BUY_USD_QUOTE_ACCEPTED_CODE: &str = "BUY_USD_QUOTE_ACCEPTED";
pub(super) const BUY_USD_QUOTE_ACCEPTED_ID: Uuid = uuid!("00000000-0000-0000-0000-000000000005");
pub(super) const REVERT_BUY_USD_QUOTE_ACCEPTED_CODE: &str = "REVERT_BUY_USD_QUOTE_ACCEPTED";
pub(super) const REVERT_BUY_USD_QUOTE_ACCEPTED_ID: Uuid =
uuid!("00000000-0000-0000-0000-100000000005");
pub(super) const SELL_USD_QUOTE_ACCEPTED_CODE: &str = "SELL_USD_QUOTE_ACCEPTED";
pub(super) const SELL_USD_QUOTE_ACCEPTED_ID: Uuid = uuid!("00000000-0000-0000-0000-000000000006");
pub(super) const REVERT_SELL_USD_QUOTE_ACCEPTED_CODE: &str = "REVERT_SELL_USD_QUOTE_ACCEPTED";
pub(super) const REVERT_SELL_USD_QUOTE_ACCEPTED_ID: Uuid =
uuid!("00000000-0000-0000-0000-100000000005");

// Journal
pub(super) const STABLESATS_JOURNAL_NAME: &str = "Stablesats";
Expand Down
111 changes: 0 additions & 111 deletions ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ impl Ledger {
templates::IncreaseExchangePosition::init(&inner).await?;
templates::DecreaseExchangePosition::init(&inner).await?;
templates::BuyUsdQuoteAccepted::init(&inner).await?;
templates::RevertBuyUsdQuoteAccepted::init(&inner).await?;
templates::SellUsdQuoteAccepted::init(&inner).await?;
templates::RevertSellUsdQuoteAccepted::init(&inner).await?;

Ok(Self {
events: inner.events(EventSubscriberOpts::default()).await?,
Expand Down Expand Up @@ -239,56 +237,6 @@ impl Ledger {
Ok(())
}

#[instrument(name = "ledger.revert_buy_usd_quote_accepted", skip(self, tx))]
pub async fn revert_buy_usd_quote_accepted(
&self,
tx: Transaction<'_, Postgres>,
id: LedgerTxId,
correlation_id: impl Into<LedgerTxId> + std::fmt::Debug,
) -> Result<(), LedgerError> {
let correlation_id = correlation_id.into();
let txs = self
.inner
.transactions()
.list_by_ids(std::iter::once(correlation_id))
.await?;
let txn = txs.get(0).ok_or(LedgerError::TransactionNotFound)?;
let metadata = txn.metadata()?.ok_or(LedgerError::MissingTxMetadata)?;
let mut satoshi_amount = None;
let mut usd_cents_amount = None;
let entries = self
.inner
.entries()
.list_by_transaction_ids(std::iter::once(correlation_id))
.await?;
for entry in entries.into_values().flatten() {
match entry.entry_type.as_str() {
"BUY_USD_QUOTE_ACCEPTED_BTC_CR" => {
satoshi_amount = Some(entry.units * SATS_PER_BTC)
}
"BUY_USD_QUOTE_ACCEPTED_USD_CR" => {
usd_cents_amount = Some(entry.units * CENTS_PER_USD)
}
_ => {}
}
}
let satoshi_amount =
satoshi_amount.ok_or(LedgerError::ExpectedEntryNotFoundInTx("satoshi amount"))?;
let usd_cents_amount =
usd_cents_amount.ok_or(LedgerError::ExpectedEntryNotFoundInTx("usd cent amount"))?;

let params = RevertBuyUsdQuoteAcceptedParams {
usd_cents_amount,
satoshi_amount,
correlation_id,
meta: metadata,
};
self.inner
.post_transaction_in_tx(tx, id, REVERT_BUY_USD_QUOTE_ACCEPTED_CODE, Some(params))
.await?;
Ok(())
}

#[instrument(name = "ledger.sell_usd_quote_accepted", skip(self, tx))]
pub async fn sell_usd_quote_accepted(
&self,
Expand All @@ -302,65 +250,6 @@ impl Ledger {
Ok(())
}

#[instrument(name = "ledger.revert_sell_usd_quote_accepted", skip(self, tx))]
pub async fn revert_sell_usd_quote_accepted(
&self,
tx: Transaction<'_, Postgres>,
id: LedgerTxId,
correlation_id: impl Into<LedgerTxId> + std::fmt::Debug,
) -> Result<(), LedgerError> {
let correlation_id = correlation_id.into();
let txs = self
.inner
.transactions()
.list_by_ids(std::iter::once(correlation_id))
.await?;
let txn = txs.get(0).ok_or(LedgerError::TransactionNotFound)?;
let metadata = txn.metadata()?.ok_or(LedgerError::MissingTxMetadata)?;
let mut satoshi_amount = None;
let mut usd_cents_amount = None;
let entries = self
.inner
.entries()
.list_by_transaction_ids(std::iter::once(correlation_id))
.await?;
for entry in entries.into_values().flatten() {
match entry.entry_type.as_str() {
"SELL_USD_QUOTE_ACCEPTED_BTC_CR" => {
satoshi_amount = Some(-entry.units * SATS_PER_BTC)
}
"SELL_USD_QUOTE_ACCEPTED_USD_CR" => {
usd_cents_amount = Some(-entry.units * CENTS_PER_USD)
}
_ => {}
}
}
let satoshi_amount =
satoshi_amount.ok_or(LedgerError::ExpectedEntryNotFoundInTx("satoshi amount"))?;
let usd_cents_amount =
usd_cents_amount.ok_or(LedgerError::ExpectedEntryNotFoundInTx("usd cent amount"))?;

let params = RevertSellUsdQuoteAcceptedParams {
usd_cents_amount,
satoshi_amount,
correlation_id,
meta: metadata,
};
self.inner
.post_transaction_in_tx(tx, id, REVERT_BUY_USD_QUOTE_ACCEPTED_CODE, Some(params))
.await?;
Ok(())
}

pub async fn usd_liability_balance_events(
&self,
) -> Result<broadcast::Receiver<SqlxLedgerEvent>, LedgerError> {
Ok(self
.events
.account_balance(STABLESATS_JOURNAL_ID.into(), STABLESATS_LIABILITY_ID.into())
.await?)
}

pub async fn usd_okex_position_balance_events(
&self,
) -> Result<broadcast::Receiver<SqlxLedgerEvent>, LedgerError> {
Expand Down
4 changes: 0 additions & 4 deletions ledger/src/templates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod buy_usd_quote_accepted;
mod decrease_exchange_position;
mod increase_exchange_position;
mod revert_buy_usd_quote_accepted;
mod revert_sell_usd_quote_accepted;
mod revert_user_buys_usd;
mod revert_user_sells_usd;
mod sell_usd_quote_accepted;
Expand All @@ -12,8 +10,6 @@ mod user_sells_usd;
pub use buy_usd_quote_accepted::*;
pub use decrease_exchange_position::*;
pub use increase_exchange_position::*;
pub use revert_buy_usd_quote_accepted::*;
pub use revert_sell_usd_quote_accepted::*;
pub use revert_user_buys_usd::*;
pub use revert_user_sells_usd::*;
pub use sell_usd_quote_accepted::*;
Expand Down
139 changes: 0 additions & 139 deletions ledger/src/templates/revert_buy_usd_quote_accepted.rs

This file was deleted.

Loading

0 comments on commit ffabbd4

Please sign in to comment.