-
Notifications
You must be signed in to change notification settings - Fork 6
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 #1 from MutinyWallet/federated-addresses
Federated Addresses
- Loading branch information
Showing
12 changed files
with
337 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::models::schema::app_user; | ||
use diesel::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive( | ||
QueryableByName, Queryable, AsChangeset, Serialize, Deserialize, Debug, Clone, PartialEq, | ||
)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
#[diesel(table_name = app_user)] | ||
pub struct AppUser { | ||
pub id: i32, | ||
pub pubkey: String, | ||
pub name: String, | ||
pub federation_id: String, | ||
pub federation_invite_code: String, | ||
} | ||
|
||
impl AppUser { | ||
pub fn get_app_users(conn: &mut PgConnection) -> anyhow::Result<Vec<AppUser>> { | ||
Ok(app_user::table.load::<Self>(conn)?) | ||
} | ||
|
||
pub fn get_by_id(conn: &mut PgConnection, user_id: i32) -> anyhow::Result<Option<AppUser>> { | ||
Ok(app_user::table | ||
.filter(app_user::id.eq(user_id)) | ||
.first::<AppUser>(conn) | ||
.optional()?) | ||
} | ||
|
||
pub fn get_by_name(conn: &mut PgConnection, name: String) -> anyhow::Result<Option<AppUser>> { | ||
Ok(app_user::table | ||
.filter(app_user::name.eq(name)) | ||
.first::<AppUser>(conn) | ||
.optional()?) | ||
} | ||
|
||
pub fn check_available_name(conn: &mut PgConnection, name: String) -> anyhow::Result<bool> { | ||
Ok(app_user::table | ||
.filter(app_user::name.eq(name)) | ||
.count() | ||
.get_result::<i64>(conn)? | ||
== 0) | ||
} | ||
|
||
pub fn get_by_pubkey( | ||
conn: &mut PgConnection, | ||
pubkey: String, | ||
) -> anyhow::Result<Option<AppUser>> { | ||
Ok(app_user::table | ||
.filter(app_user::pubkey.eq(pubkey)) | ||
.first::<AppUser>(conn) | ||
.optional()?) | ||
} | ||
} | ||
|
||
#[derive(Insertable)] | ||
#[diesel(table_name = app_user)] | ||
pub struct NewAppUser { | ||
pub pubkey: String, | ||
pub name: String, | ||
pub federation_id: String, | ||
pub federation_invite_code: String, | ||
} | ||
|
||
impl NewAppUser { | ||
pub fn insert(&self, conn: &mut PgConnection) -> anyhow::Result<AppUser> { | ||
diesel::insert_into(app_user::table) | ||
.values(self) | ||
.get_result::<AppUser>(conn) | ||
.map_err(|e| e.into()) | ||
} | ||
} |
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,64 @@ | ||
use crate::models::schema::invoice; | ||
use diesel::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive( | ||
QueryableByName, | ||
Queryable, | ||
Insertable, | ||
AsChangeset, | ||
Serialize, | ||
Deserialize, | ||
Debug, | ||
Clone, | ||
PartialEq, | ||
)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
#[diesel(table_name = invoice)] | ||
pub struct Invoice { | ||
pub id: i32, | ||
pub federation_id: String, | ||
pub op_id: String, | ||
pub app_user_id: i32, | ||
pub bolt11: String, | ||
pub amount: i64, | ||
pub state: i32, | ||
} | ||
|
||
impl Invoice { | ||
pub fn insert(&self, conn: &mut PgConnection) -> anyhow::Result<()> { | ||
diesel::insert_into(invoice::table) | ||
.values(self) | ||
.execute(conn)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn get_invoices(conn: &mut PgConnection) -> anyhow::Result<Vec<Invoice>> { | ||
Ok(invoice::table.load::<Self>(conn)?) | ||
} | ||
|
||
pub fn get_by_id(conn: &mut PgConnection, user_id: i32) -> anyhow::Result<Option<Invoice>> { | ||
Ok(invoice::table | ||
.filter(invoice::id.eq(user_id)) | ||
.first::<Invoice>(conn) | ||
.optional()?) | ||
} | ||
|
||
pub fn get_by_operation( | ||
conn: &mut PgConnection, | ||
op_id: String, | ||
) -> anyhow::Result<Option<Invoice>> { | ||
Ok(invoice::table | ||
.filter(invoice::op_id.eq(op_id)) | ||
.first::<Invoice>(conn) | ||
.optional()?) | ||
} | ||
|
||
pub fn get_by_state(conn: &mut PgConnection, state: i32) -> anyhow::Result<Option<Invoice>> { | ||
Ok(invoice::table | ||
.filter(invoice::state.eq(state)) | ||
.first::<Invoice>(conn) | ||
.optional()?) | ||
} | ||
} |
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,4 @@ | ||
pub mod app_user; | ||
pub mod invoice; | ||
mod schema; | ||
pub mod zaps; |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::models::schema::zaps; | ||
use diesel::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive( | ||
QueryableByName, | ||
Queryable, | ||
Insertable, | ||
AsChangeset, | ||
Serialize, | ||
Deserialize, | ||
Debug, | ||
Clone, | ||
PartialEq, | ||
)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
#[diesel(table_name = zaps)] | ||
pub struct Zap { | ||
pub id: i32, | ||
pub request: String, | ||
pub event_id: Option<String>, | ||
} | ||
|
||
impl Zap { | ||
pub fn insert(&self, conn: &mut PgConnection) -> anyhow::Result<()> { | ||
diesel::insert_into(zaps::table) | ||
.values(self) | ||
.execute(conn)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn get_zaps(conn: &mut PgConnection) -> anyhow::Result<Vec<Zap>> { | ||
Ok(zaps::table.load::<Self>(conn)?) | ||
} | ||
|
||
pub fn get_by_id(conn: &mut PgConnection, zap_id: i32) -> anyhow::Result<Option<Zap>> { | ||
Ok(zaps::table | ||
.filter(zaps::id.eq(zap_id)) | ||
.first::<Zap>(conn) | ||
.optional()?) | ||
} | ||
|
||
pub fn set_event_id(&self, conn: &mut PgConnection, event_id: String) -> anyhow::Result<()> { | ||
diesel::update(zaps::table) | ||
.filter(zaps::id.eq(self.id)) | ||
.set(zaps::event_id.eq(event_id)) | ||
.execute(conn)?; | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.