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

Optional request id - to be checked and compiled #385

Merged
merged 4 commits into from
Nov 7, 2024
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,450 changes: 891 additions & 559 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ uuid = { version = "1.8.0", features = [
"serde",
] }
reqwest = { version = "0.12.1", features = ["json"] }
mostro-core = { version = "0.6.10", features = ["sqlx"] }
mostro-core = { version = "0.6.11", features = ["sqlx"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
config = "0.14.0"
clap = { version = "4.5.19", features = ["derive"] }
lnurl-rs = "0.8.0"
openssl = { version = "0.10.66", features = ["vendored"] }
once_cell = "1.20.2"
once_cell = "1.20.2"
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "1.82.0"
profile = "minimal"
components = ["clippy", "rust-docs", "rustfmt"]
targets = ["wasm32-unknown-unknown"]
49 changes: 19 additions & 30 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,21 @@ pub async fn run(
match message {
Ok(msg) => {
if msg.get_inner_message_kind().verify() {
// Get the optional request id
let request_id = msg.get_inner_message_kind().request_id;

if let Some(action) = msg.inner_action() {
match action {
Action::NewOrder => {
if let Err(e) = order_action(
msg, &event, &my_keys, &pool, request_id,
)
.await
if let Err(e) =
order_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
Action::TakeSell => {
if let Err(e) = take_sell_action(
msg, &event, &my_keys, &pool, request_id,
)
.await
if let Err(e) =
take_sell_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
Expand All @@ -114,17 +111,15 @@ pub async fn run(
}
}
Action::FiatSent => {
if let Err(e) = fiat_sent_action(
msg, &event, &my_keys, &pool, request_id,
)
.await
if let Err(e) =
fiat_sent_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
Action::Release => {
if let Err(e) = release_action(
msg, &event, &my_keys, &pool, ln_client, request_id,
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
Expand All @@ -133,18 +128,17 @@ pub async fn run(
}
Action::Cancel => {
if let Err(e) = cancel_action(
msg, &event, &my_keys, &pool, ln_client, request_id,
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
warning_msg(&action, e)
}
}
Action::AddInvoice => {
if let Err(e) = add_invoice_action(
msg, &event, &my_keys, &pool, request_id,
)
.await
if let Err(e) =
add_invoice_action(msg, &event, &my_keys, &pool)
.await
{
warning_msg(&action, e)
}
Expand All @@ -157,25 +151,22 @@ pub async fn run(
&my_keys,
&pool,
rate_list.clone(),
request_id,
)
.await
{
warning_msg(&action, e)
}
}
Action::Dispute => {
if let Err(e) = dispute_action(
msg, &event, &my_keys, &pool, request_id,
)
.await
if let Err(e) =
dispute_action(msg, &event, &my_keys, &pool).await
{
warning_msg(&action, e)
}
}
Action::AdminCancel => {
if let Err(e) = admin_cancel_action(
msg, &event, &my_keys, &pool, ln_client, request_id,
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
Expand All @@ -184,7 +175,7 @@ pub async fn run(
}
Action::AdminSettle => {
if let Err(e) = admin_settle_action(
msg, &event, &my_keys, &pool, ln_client, request_id,
msg, &event, &my_keys, &pool, ln_client,
)
.await
{
Expand All @@ -193,18 +184,16 @@ pub async fn run(
}
Action::AdminAddSolver => {
if let Err(e) = admin_add_solver_action(
msg, &event, &my_keys, &pool, request_id,
msg, &event, &my_keys, &pool,
)
.await
{
warning_msg(&action, e)
}
}
Action::AdminTakeDispute => {
if let Err(e) = admin_take_dispute_action(
msg, &event, &pool, request_id,
)
.await
if let Err(e) =
admin_take_dispute_action(msg, &event, &pool).await
{
warning_msg(&action, e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/add_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub async fn add_invoice_action(
event: &UnwrappedGift,
my_keys: &Keys,
pool: &Pool<Sqlite>,
request_id: u64,
) -> Result<()> {
let order_msg = msg.get_inner_message_kind();
let request_id = msg.get_inner_message_kind().request_id;
let mut order = if let Some(order_id) = order_msg.id {
match Order::by_id(pool, order_id).await? {
Some(order) => order,
Expand Down
4 changes: 3 additions & 1 deletion src/app/admin_add_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ pub async fn admin_add_solver_action(
event: &UnwrappedGift,
my_keys: &Keys,
pool: &Pool<Sqlite>,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let inner_message = msg.get_inner_message_kind();
let content = if let Some(content) = &inner_message.content {
content
Expand Down
4 changes: 3 additions & 1 deletion src/app/admin_cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ pub async fn admin_cancel_action(
my_keys: &Keys,
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/app/admin_settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ pub async fn admin_settle_action(
my_keys: &Keys,
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
Expand Down Expand Up @@ -164,7 +166,7 @@ pub async fn admin_settle_action(
.await?;
}

let _ = do_payment(order_updated, Some(request_id)).await;
let _ = do_payment(order_updated, request_id).await;

Ok(())
}
4 changes: 3 additions & 1 deletion src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ pub async fn admin_take_dispute_action(
msg: Message,
event: &UnwrappedGift,
pool: &Pool<Sqlite>,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

// Find dipute id in the message
let dispute_id = if let Some(dispute_id) = msg.get_inner_message_kind().id {
dispute_id
Expand Down
8 changes: 5 additions & 3 deletions src/app/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ pub async fn cancel_action(
my_keys: &Keys,
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
Expand Down Expand Up @@ -178,7 +180,7 @@ pub async fn cancel_add_invoice(
event: &UnwrappedGift,
pool: &Pool<Sqlite>,
my_keys: &Keys,
request_id: u64,
request_id: Option<u64>,
) -> Result<()> {
if let Some(hash) = &order.hash {
ln_client.cancel_hold_invoice(hash).await?;
Expand Down Expand Up @@ -245,7 +247,7 @@ pub async fn cancel_pay_hold_invoice(
event: &UnwrappedGift,
pool: &Pool<Sqlite>,
my_keys: &Keys,
request_id: u64,
request_id: Option<u64>,
) -> Result<()> {
if order.hash.is_some() {
// We return funds to seller
Expand Down
4 changes: 3 additions & 1 deletion src/app/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ pub async fn dispute_action(
event: &UnwrappedGift,
my_keys: &Keys,
pool: &Pool<Sqlite>,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/app/fiat_sent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub async fn fiat_sent_action(
event: &UnwrappedGift,
my_keys: &Keys,
pool: &Pool<Sqlite>,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/app/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ pub async fn order_action(
event: &UnwrappedGift,
my_keys: &Keys,
pool: &Pool<Sqlite>,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

if let Some(order) = msg.get_inner_message_kind().get_order() {
let mostro_settings = Settings::get_mostro();

Expand Down
4 changes: 3 additions & 1 deletion src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ pub async fn update_user_reputation_action(
my_keys: &Keys,
pool: &Pool<Sqlite>,
rate_list: Arc<Mutex<Vec<Event>>>,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
Expand Down
14 changes: 8 additions & 6 deletions src/app/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub async fn check_failure_retries(order: &Order, request_id: Option<u64>) -> Re
};

send_new_order_msg(
request_id.unwrap_or(1),
request_id,
Some(order.id),
Action::PaymentFailed,
None,
Expand All @@ -64,8 +64,10 @@ pub async fn release_action(
my_keys: &Keys,
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
request_id: u64,
) -> Result<()> {
// Get request id
let request_id = msg.get_inner_message_kind().request_id;

// Check if order id is ok
let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
Expand Down Expand Up @@ -152,7 +154,7 @@ pub async fn release_action(
)
.await;

let _ = do_payment(order_updated, Some(request_id)).await;
let _ = do_payment(order_updated, request_id).await;

Ok(())
}
Expand All @@ -177,7 +179,7 @@ pub async fn do_payment(mut order: Order, request_id: Option<u64>) -> Result<()>
let payment_task = ln_client_payment.send_payment(&payment_request, amount as i64, tx);
if let Err(paymement_result) = payment_task.await {
info!("Error during ln payment : {}", paymement_result);
if let Ok(failed_payment) = check_failure_retries(&order, None).await {
if let Ok(failed_payment) = check_failure_retries(&order, request_id).await {
info!(
"Order id {} has {} failed payments retries",
failed_payment.id, failed_payment.payment_attempts
Expand Down Expand Up @@ -213,7 +215,7 @@ pub async fn do_payment(mut order: Order, request_id: Option<u64>) -> Result<()>
&buyer_pubkey,
&seller_pubkey,
&my_keys,
request_id.unwrap_or(1),
request_id,
)
.await;
}
Expand Down Expand Up @@ -248,7 +250,7 @@ async fn payment_success(
buyer_pubkey: &PublicKey,
seller_pubkey: &PublicKey,
my_keys: &Keys,
request_id: u64,
request_id: Option<u64>,
) -> Result<()> {
// Purchase completed message to buyer
send_new_order_msg(
Expand Down
Loading
Loading