-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
1 deletion.
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
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,32 @@ | ||
use tracing::instrument; | ||
|
||
use super::error::*; | ||
use crate::{account::*, dev_constants, ledger::Ledger, primitives::bitcoin, profile::*}; | ||
|
||
const BOOTSTRAP_KEY_NAME: &str = "payjoin_bootstrap_key"; | ||
|
||
pub struct PayjoinApp { | ||
accounts: Accounts, | ||
profiles: Profiles, | ||
ledger: Ledger, | ||
pool: sqlx::PgPool, | ||
network: bitcoin::Network, | ||
} | ||
|
||
impl PayjoinApp { | ||
pub fn new(pool: sqlx::PgPool, network: bitcoin::Network) -> Self { | ||
Self { | ||
accounts: Accounts::new(&pool), | ||
profiles: Profiles::new(&pool), | ||
ledger: Ledger::new(&pool), | ||
pool, | ||
network, | ||
} | ||
} | ||
} | ||
|
||
impl PayjoinApp { | ||
pub fn run() { | ||
println!("run PayjoinApp"); | ||
} | ||
} |
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,18 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct PayjoinConfig { | ||
#[serde(default = "default_port")] | ||
pub listen_port: u16, | ||
} | ||
impl Default for PayjoinConfig { | ||
fn default() -> Self { | ||
Self { | ||
listen_port: default_port(), | ||
} | ||
} | ||
} | ||
|
||
fn default_port() -> u16 { | ||
8088 | ||
} |
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,8 @@ | ||
use thiserror::Error; | ||
|
||
#[allow(clippy::large_enum_variant)] | ||
#[derive(Error, Debug)] | ||
pub enum PayjoinApiError { | ||
#[error("PayjoinApiError - Error")] | ||
Error, | ||
} |
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,68 @@ | ||
mod app; | ||
mod config; | ||
pub mod error; | ||
mod server; | ||
|
||
pub use app::*; | ||
pub use config::*; | ||
pub use error::*; | ||
pub use server::*; | ||
|
||
// pub async fn run_dev( | ||
// pool: sqlx::PgPool, | ||
// config: ApiConfig, | ||
// app_cfg: AppConfig, | ||
// xpub: Option<(String, String)>, | ||
// derivation_path: Option<String>, | ||
// ) -> Result<(), ApplicationError> { | ||
// use crate::{ | ||
// dev_constants, | ||
// payout_queue::*, | ||
// profile::Profiles, | ||
// xpub::{BitcoindSignerConfig, SignerConfig}, | ||
// }; | ||
|
||
// let app = App::run(pool.clone(), app_cfg).await?; | ||
// if let Some((xpub, signer_endpoint)) = xpub { | ||
// println!("Creating dev entities"); | ||
// let profile = Profiles::new(&pool) | ||
// .find_by_key(dev_constants::BRIA_DEV_KEY) | ||
// .await?; | ||
// let (_, xpubs) = app | ||
// .create_wpkh_wallet( | ||
// &profile, | ||
// dev_constants::DEV_WALLET_NAME.to_string(), | ||
// xpub, | ||
// derivation_path, | ||
// ) | ||
// .await?; | ||
// app.set_signer_config( | ||
// &profile, | ||
// xpubs[0].to_string(), | ||
// SignerConfig::Bitcoind(BitcoindSignerConfig { | ||
// endpoint: signer_endpoint, | ||
// rpc_user: dev_constants::DEFAULT_BITCOIND_RPC_USER.to_string(), | ||
// rpc_password: dev_constants::DEFAULT_BITCOIND_RPC_PASSWORD.to_string(), | ||
// }), | ||
// ) | ||
// .await?; | ||
// app.create_payout_queue( | ||
// &profile, | ||
// dev_constants::DEV_QUEUE_NAME.to_string(), | ||
// None, | ||
// Some(PayoutQueueConfig { | ||
// trigger: PayoutQueueTrigger::Payjoin, | ||
// ..PayoutQueueConfig::default() | ||
// }), | ||
// ) | ||
// .await?; | ||
// } | ||
// server::start(config, app).await?; | ||
// Ok(()) | ||
// } | ||
|
||
pub async fn run(pool: sqlx::PgPool, config: PayjoinConfig) -> Result<(), PayjoinApiError> { | ||
let app = PayjoinApp::run().await?; | ||
server::start(config, app).await?; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::payjoin::PayjoinApiError; | ||
|
||
impl From<PayjoinApiError> for tonic::Status { | ||
fn from(err: PayjoinApiError) -> Self { | ||
tonic::Status::new(tonic::Code::Unknown, format!("{err}")) | ||
} | ||
} |
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,41 @@ | ||
mod convert; | ||
|
||
use futures::StreamExt; | ||
use opentelemetry::propagation::{Extractor, TextMapPropagator}; | ||
use opentelemetry_sdk::propagation::TraceContextPropagator; | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
use tracing::instrument; | ||
use tracing_opentelemetry::OpenTelemetrySpanExt; | ||
|
||
use super::{config::*, PayjoinApp}; | ||
use crate::{ | ||
app::{error::ApplicationError, *}, | ||
payout_queue, | ||
primitives::*, | ||
profile, | ||
}; | ||
|
||
pub const PROFILE_API_KEY_HEADER: &str = "x-bria-payjoin-api-key"; | ||
|
||
pub struct Payjoin { | ||
app: PayjoinApp, | ||
} | ||
|
||
#[tonic::async_trait] | ||
impl PayjoinService for Payjoin {} | ||
|
||
pub(crate) async fn start( | ||
server_config: PayjoinConfig, | ||
app: PayjoinApp, | ||
) -> Result<(), PayjoinApiError> { | ||
let payjoin = Payjoin { app }; | ||
println!( | ||
"Starting payjoin server on port {}", | ||
server_config.listen_port | ||
); | ||
|
||
Server::builder() | ||
.serve(([0, 0, 0, 0], server_config.listen_port).into()) | ||
.await?; | ||
Ok(()) | ||
} |