Skip to content

Commit

Permalink
Fix: sends right index on first operation
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Jan 3, 2025
1 parent 49be68b commit 617aa5c
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub async fn run() -> Result<()> {
let (trade_keys, trade_index) = User::get_next_trade_keys(&pool)
.await
.map_err(|e| anyhow::anyhow!("Failed to get trade keys: {}", e))?;

// Mostro pubkey
let mostro_key = PublicKey::from_str(&pubkey)?;

Expand Down
2 changes: 1 addition & 1 deletion src/cli/get_dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub async fn execute_get_dm(
// Update last trade index
match User::get(&pool).await {
Ok(mut user) => {
user.set_last_trade_index(trade_index + 1);
user.set_last_trade_index(trade_index);
if let Err(e) = user.save(&pool).await {
println!("Failed to update user: {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/new_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub async fn execute_new_order(
// Update last trade index
match User::get(&pool).await {
Ok(mut user) => {
user.set_last_trade_index(trade_index + 1);
user.set_last_trade_index(trade_index);
if let Err(e) = user.save(&pool).await {
println!("Failed to update user: {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/send_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn execute_send_msg(
// Update last trade index
match User::get(&pool).await {
Ok(mut user) => {
user.set_last_trade_index(trade_index + 1);
user.set_last_trade_index(trade_index);
if let Err(e) = user.save(&pool).await {
println!("Failed to update user: {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/take_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub async fn execute_take_buy(
// Update last trade index to be used in next trade
match User::get(&pool).await {
Ok(mut user) => {
user.set_last_trade_index(trade_index + 1);
user.set_last_trade_index(trade_index);
if let Err(e) = user.save(&pool).await {
println!("Failed to update user: {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/take_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub async fn execute_take_sell(
// Update last trade index to be used in next trade
match User::get(&pool).await {
Ok(mut user) => {
user.set_last_trade_index(trade_index + 1);
user.set_last_trade_index(trade_index);
if let Err(e) = user.save(&pool).await {
println!("Failed to update user: {}", e);
}
Expand Down
3 changes: 1 addition & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ impl User {
}

pub async fn get_next_trade_keys(pool: &SqlitePool) -> Result<(Keys, i64)> {
let mut trade_index = User::get_next_trade_index(pool.clone()).await?;
trade_index -= 1;
let trade_index = User::get_next_trade_index(pool.clone()).await?;

let user = User::get(pool).await?;
let account = NOSTR_REPLACEABLE_EVENT_KIND as u32;
Expand Down

0 comments on commit 617aa5c

Please sign in to comment.