Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sends right index on first operation #110

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading