Skip to content

Commit

Permalink
fix: pairing of ln user-trades
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Sep 20, 2022
1 parent d3b79e7 commit 5359f0b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 50 deletions.
84 changes: 42 additions & 42 deletions user-trades/sqlx-data.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,5 @@
{
"db": "PostgreSQL",
"14d985ef639ed93ae82020835741cc9bf8189ac0c0abd09e04bf2734c8fae103": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Varchar"
},
{
"name": "settlement_amount",
"ordinal": 1,
"type_info": "Numeric"
},
{
"name": "settlement_currency",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "amount_in_usd_cents",
"ordinal": 3,
"type_info": "Numeric"
},
{
"name": "created_at",
"ordinal": 4,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false
],
"parameters": {
"Left": []
}
},
"query": "\n SELECT id, settlement_amount, settlement_currency, amount_in_usd_cents, created_at\n FROM galoy_transactions\n WHERE is_paired = false AND settlement_method = 'SettlementViaIntraLedger' AND amount_in_usd_cents != 0 FOR UPDATE\n "
},
"2bd20eee766a5eb278d25c67fb87c998f20a5af7c02a0b05c175af3d6464f9f7": {
"describe": {
"columns": [
Expand Down Expand Up @@ -195,5 +153,47 @@
}
},
"query": "SELECT id, cursor FROM galoy_transactions WHERE is_latest_cursor = 'true'"
},
"f1353aa7ecf75375f32be2736a51f09fb13ed8492a0a3c51659743fa0a47b3ab": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Varchar"
},
{
"name": "settlement_amount",
"ordinal": 1,
"type_info": "Numeric"
},
{
"name": "settlement_currency",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "amount_in_usd_cents",
"ordinal": 3,
"type_info": "Numeric"
},
{
"name": "created_at",
"ordinal": 4,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false
],
"parameters": {
"Left": []
}
},
"query": "\n SELECT id, settlement_amount, settlement_currency, amount_in_usd_cents, created_at\n FROM galoy_transactions\n WHERE is_paired = false AND amount_in_usd_cents != 0 FOR UPDATE\n "
}
}
8 changes: 5 additions & 3 deletions user-trades/src/galoy_transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ impl GaloyTransactions {
&self,
) -> Result<UnpairedTransactions, UserTradesError> {
let mut tx = self.pool.begin().await?;
let res = sqlx::query!("
let res = sqlx::query!(
"
SELECT id, settlement_amount, settlement_currency, amount_in_usd_cents, created_at
FROM galoy_transactions
WHERE is_paired = false AND settlement_method = 'SettlementViaIntraLedger' AND amount_in_usd_cents != 0 FOR UPDATE
")
WHERE is_paired = false AND amount_in_usd_cents != 0 FOR UPDATE
"
)
.fetch_all(&mut tx)
.await?;
Ok(UnpairedTransactions {
Expand Down
6 changes: 1 addition & 5 deletions user-trades/src/job/poll_galoy_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ fn is_pair(tx1: &UnpairedTransaction, tx2: &UnpairedTransaction) -> bool {
return false;
}

if tx1.settlement_currency == SettlementCurrency::BTC {
tx1.amount_in_usd_cents.abs() == tx2.settlement_amount.abs()
} else {
tx2.amount_in_usd_cents.abs() == tx1.settlement_amount.abs()
}
tx1.amount_in_usd_cents.abs() == tx2.amount_in_usd_cents.abs()
}

impl From<SettlementCurrency> for UserTradeUnit {
Expand Down

0 comments on commit 5359f0b

Please sign in to comment.