Skip to content

Commit 63dfb50

Browse files
committed
add debug logs for db
1 parent 7998ade commit 63dfb50

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

crates/coin-selection/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ bincode = { workspace = true }
1313
contracts = { workspace = true }
1414
contracts-adapter = { workspace = true }
1515
global-utils = { workspace = true }
16+
hex = { workspace = true }
17+
reqwest = { workspace = true }
1618
serde = { workspace = true }
1719
simplicity-lang = { workspace = true }
1820
simplicityhl = { workspace = true }
1921
simplicityhl-core = { workspace = true }
2022
sqlx = { workspace = true }
2123
tokio = { workspace = true }
22-
reqwest = { workspace = true }
23-
hex = { workspace = true }
24+
tracing = { workspace = true }
2425

2526
[dev-dependencies]
2627
dotenvy = { workspace = true }

crates/coin-selection/src/sqlite_db.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use contracts::DCDArguments;
66
use simplicityhl::elements::OutPoint;
77
use sqlx::{Connection, Sqlite, SqlitePool, migrate::MigrateDatabase};
88
use std::path::PathBuf;
9+
use tracing::instrument;
910

1011
const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
1112

@@ -76,7 +77,10 @@ impl SqliteRepo {
7677

7778
#[async_trait]
7879
impl CoinSelectionStorage for SqliteRepo {
80+
#[instrument(level = "debug", skip_all, err)]
7981
async fn mark_outpoints_spent(&self, outpoints: &[OutPoint]) -> Result<()> {
82+
tracing::debug!("Input params, outpoints: {outpoints:?}");
83+
8084
// mark given outpoints as spent in a single transaction
8185
let mut tx = self.pool.begin().await?;
8286
for op in outpoints {
@@ -96,7 +100,10 @@ impl CoinSelectionStorage for SqliteRepo {
96100
Ok(())
97101
}
98102

103+
#[instrument(level = "debug", skip_all, err)]
99104
async fn add_outpoint(&self, info: OutPointInfo) -> Result<()> {
105+
tracing::debug!("Input params, info: {info:?}");
106+
100107
sqlx::query(
101108
r#"
102109
INSERT INTO outpoints (tx_id, vout, owner_script_pubkey, asset_id, spent)
@@ -118,7 +125,10 @@ impl CoinSelectionStorage for SqliteRepo {
118125
Ok(())
119126
}
120127

128+
#[instrument(level = "debug", skip_all, err)]
121129
async fn get_token_outpoints(&self, filter: GetTokenFilter) -> Result<Vec<OutPointInfoRaw>> {
130+
tracing::debug!("Input params, filter: {filter:?}");
131+
122132
let base = "SELECT id, tx_id, vout, owner_script_pubkey, asset_id, spent FROM outpoints";
123133
let where_clause = filter.get_sql_filter();
124134
let query = format!("{base}{where_clause}");
@@ -158,7 +168,9 @@ impl CoinSelectionStorage for SqliteRepo {
158168

159169
#[async_trait]
160170
impl DcdParamsStorage for SqliteRepo {
171+
#[instrument(level = "debug", skip_all, err)]
161172
async fn add_dcd_params(&self, taproot_pubkey_gen: &str, dcd_args: &DCDArguments) -> Result<()> {
173+
tracing::debug!("Input params, taproot: {taproot_pubkey_gen}, dcd_args: {dcd_args:?}");
162174
let serialized = bincode::encode_to_vec(dcd_args, bincode::config::standard())?;
163175

164176
sqlx::query(
@@ -174,7 +186,9 @@ impl DcdParamsStorage for SqliteRepo {
174186
Ok(())
175187
}
176188

189+
#[instrument(level = "debug", skip_all, err)]
177190
async fn get_dcd_params(&self, taproot_pubkey_gen: &str) -> Result<Option<DCDArguments>> {
191+
tracing::debug!("Input params, taproot: {taproot_pubkey_gen}");
178192
let row = sqlx::query_as::<_, (Vec<u8>,)>("SELECT dcd_args_blob FROM dcd_params WHERE taproot_pubkey_gen = ?")
179193
.bind(taproot_pubkey_gen)
180194
.fetch_optional(&self.pool)
@@ -192,6 +206,7 @@ impl DcdParamsStorage for SqliteRepo {
192206

193207
#[async_trait]
194208
impl EntropyStorage for SqliteRepo {
209+
#[instrument(level = "debug", skip_all, err)]
195210
async fn add_dcd_contract_token_entropies(
196211
&self,
197212
taproot_pubkey_gen: &str,
@@ -212,6 +227,7 @@ impl EntropyStorage for SqliteRepo {
212227
Ok(())
213228
}
214229

230+
#[instrument(level = "debug", skip_all, err)]
215231
async fn get_dcd_contract_token_entropies(
216232
&self,
217233
taproot_pubkey_gen: &str,

crates/coin-selection/src/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub trait CoinSelector: Send + Sync + CoinSelectionStorage + DcdParamsStorage +
9494
TransactionOption::TakerTerminationEarly(_) => {}
9595
TransactionOption::TakerSettlement(_) => {}
9696
TransactionOption::MakerFund(order) => {
97+
// TODO: add fetching of only needed outs - not all
9798
let fetched_transaction = fetch_tx(order).await?;
9899
let mut outpoints_to_add =
99100
Vec::with_capacity(fetched_transaction.input.len() + fetched_transaction.output.len());
@@ -104,6 +105,10 @@ pub trait CoinSelector: Send + Sync + CoinSelectionStorage + DcdParamsStorage +
104105
outpoints_to_add
105106
.push(extract_outpoint_info_from_tx_out(OutPoint::new(order, i as u32), tx_out).await?);
106107
}
108+
for outpoint in outpoints_to_add {
109+
tracing::debug!("[Coinselector] Adding outpoint {:?}", outpoint);
110+
self.add_outpoint(outpoint).await?;
111+
}
107112
}
108113
TransactionOption::MakerTerminationCollateral(_) => {}
109114
TransactionOption::MakerTerminationSettlement(_) => {}

0 commit comments

Comments
 (0)