-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2174 from get10101/chore/block-users-from-trading…
…-with-old-versions feat(trade): Block users from trading with an old app version
- Loading branch information
Showing
30 changed files
with
129 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
coordinator/migrations/2024-03-06-1135500_add_version_to_user/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE users DROP COLUMN IF EXISTS "version"; |
1 change: 1 addition & 0 deletions
1
coordinator/migrations/2024-03-06-1135500_add_version_to_user/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE users ADD COLUMN "version" TEXT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::db; | ||
use crate::db::user::User; | ||
use anyhow::ensure; | ||
use anyhow::Context; | ||
use anyhow::Result; | ||
use bitcoin::secp256k1::PublicKey; | ||
use diesel::PgConnection; | ||
|
||
pub fn check_version(conn: &mut PgConnection, trader_id: &PublicKey) -> Result<()> { | ||
let user: User = db::user::get_user(conn, trader_id)?.context("Couldn't find user")?; | ||
|
||
let app_version = user.version.context("No version found")?; | ||
|
||
let coordinator_version = env!("CARGO_PKG_VERSION").to_string(); | ||
ensure!( | ||
app_version == coordinator_version, | ||
format!("Please upgrade to the latest version: {coordinator_version}") | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,16 +22,18 @@ async fn registered_user_is_stored_in_db() { | |
let dummy_email = "[email protected]".to_string(); | ||
let nickname = Some("dummy_user".to_string()); | ||
let fcm_token = "just_a_token".to_string(); | ||
let version = Some("1.9.0".to_string()); | ||
|
||
let user = user::upsert_user( | ||
&mut conn, | ||
dummy_pubkey, | ||
Some(dummy_email.clone()), | ||
nickname.clone(), | ||
version.clone(), | ||
) | ||
.unwrap(); | ||
assert!(user.id.is_some(), "Id should be filled in by diesel"); | ||
user::login_user(&mut conn, dummy_pubkey, fcm_token.clone()).unwrap(); | ||
user::login_user(&mut conn, dummy_pubkey, fcm_token.clone(), version.clone()).unwrap(); | ||
|
||
let users = user::all(&mut conn).unwrap(); | ||
assert_eq!(users.len(), 1); | ||
|
@@ -40,6 +42,7 @@ async fn registered_user_is_stored_in_db() { | |
assert_eq!(users.first().unwrap().contact, dummy_email); | ||
assert_eq!(users.first().unwrap().nickname, nickname); | ||
assert_eq!(users.first().unwrap().fcm_token, fcm_token); | ||
assert_eq!(users.first().unwrap().version, version); | ||
} | ||
|
||
fn dummy_public_key() -> PublicKey { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "native" | ||
version = "0.1.0" | ||
version = "1.9.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
|
Oops, something went wrong.