From ee626bfa6172e5d5da8992f94205bd01102eb1aa Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 30 Jun 2023 13:52:09 -0700 Subject: [PATCH 01/11] lint --- web3_proxy/tests/test_users.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/web3_proxy/tests/test_users.rs b/web3_proxy/tests/test_users.rs index edae850d..5603c8b8 100644 --- a/web3_proxy/tests/test_users.rs +++ b/web3_proxy/tests/test_users.rs @@ -1,11 +1,8 @@ mod common; use crate::common::TestApp; -use axum::headers::Authorization; use ethers::{signers::Signer, types::Signature}; -use hashbrown::HashMap; use serde::Deserialize; -use serde_json::Value; use tracing::{debug, info, trace}; use ulid::Ulid; use web3_proxy::frontend::users::authentication::PostLogin; @@ -14,10 +11,10 @@ use web3_proxy::frontend::users::authentication::PostLogin; #[derive(Debug, Deserialize)] struct LoginPostResponse { pub bearer_token: Ulid, - pub rpc_keys: Value, - /// unknown data gets put here - #[serde(flatten, default = "HashMap::default")] - pub extra: HashMap, + // pub rpc_keys: Value, + // /// unknown data gets put here + // #[serde(flatten, default = "HashMap::default")] + // pub extra: HashMap, } /// TODO: 191 and the other message formats in another test From 7044edc63c02534289563dcf8973fca256c3bda4 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 1 Jul 2023 09:10:53 -0700 Subject: [PATCH 02/11] check multiple posible stripe headers --- web3_proxy/src/frontend/users/payment_stripe.rs | 16 ++++++++++++---- web3_proxy/tests/test_proxy.rs | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs index f442df63..00507245 100644 --- a/web3_proxy/src/frontend/users/payment_stripe.rs +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -101,11 +101,19 @@ pub async fn user_balance_stripe_post( // ))?; // TODO Get this from the header - let signature = headers - .get("STRIPE_SIGNATURE") - .ok_or(Web3ProxyError::BadRequest( + let signature = if let Some(x) = headers.get("stripe-signature") { + x + } else if let Some(x) = headers.get("STRIPE_SIGNATURE") { + x + } else if let Some(x) = headers.get("HTTP_STRIPE_SIGNATURE") { + x + } else { + return Err(Web3ProxyError::BadRequest( "You have not provided a 'STRIPE_SIGNATURE' for the Stripe payload".into(), - ))? + )); + }; + + let signature = signature .to_str() .web3_context("Could not parse stripe signature as byte-string")?; diff --git a/web3_proxy/tests/test_proxy.rs b/web3_proxy/tests/test_proxy.rs index dd6c5e90..e58134ef 100644 --- a/web3_proxy/tests/test_proxy.rs +++ b/web3_proxy/tests/test_proxy.rs @@ -10,7 +10,7 @@ use tokio::{ }; use web3_proxy::rpcs::blockchain::ArcBlock; -#[cfg_attr(not(feature = "tests-needing-docker"), ignore)] +// #[cfg_attr(not(feature = "tests-needing-docker"), ignore)] #[ignore = "under construction"] #[test_log::test(tokio::test)] async fn it_migrates_the_db() { From 377cd8bcf38e32341b58e2ccc5c8dde9cc061c52 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 1 Jul 2023 09:12:50 -0700 Subject: [PATCH 03/11] one more stripe option need to check if case matters --- web3_proxy/src/frontend/users/payment_stripe.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs index 00507245..35a0a29f 100644 --- a/web3_proxy/src/frontend/users/payment_stripe.rs +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -103,6 +103,8 @@ pub async fn user_balance_stripe_post( // TODO Get this from the header let signature = if let Some(x) = headers.get("stripe-signature") { x + } else if let Some(x) = headers.get("Stripe-Signature") { + x } else if let Some(x) = headers.get("STRIPE_SIGNATURE") { x } else if let Some(x) = headers.get("HTTP_STRIPE_SIGNATURE") { From 832432e9d4d550b8b38622f926db92e0c2c699f8 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 2 Jul 2023 16:21:10 -0700 Subject: [PATCH 04/11] cargo upgrade --- Cargo.lock | 29 ++++++++++------------------- web3_proxy/Cargo.toml | 4 ++-- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fab0f78..ce118b79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" dependencies = [ "gimli", ] @@ -566,15 +566,15 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.67" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" dependencies = [ "addr2line", "cc", "cfg-if", "libc", - "miniz_oxide 0.6.2", + "miniz_oxide", "object", "rustc-demangle", ] @@ -2161,7 +2161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", - "miniz_oxide 0.7.1", + "miniz_oxide", ] [[package]] @@ -3381,15 +3381,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -3673,9 +3664,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.4" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" dependencies = [ "memchr", ] @@ -4542,9 +4533,9 @@ dependencies = [ [[package]] name = "rdkafka" -version = "0.32.2" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8733bc5dc0b192d1a4b28073f9bff1326ad9e4fecd4d9b025d6fc358d1c3e79" +checksum = "8c613d9892f835d4593a769ee274716b0c4403b80e8f57ac0f773b815738cda8" dependencies = [ "futures-channel", "futures-util", diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 90024eeb..f26b78c7 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -82,7 +82,7 @@ pagerduty-rs = { version = "0.1.6", default-features = false, features = ["async parking_lot = { version = "0.12.1", features = ["arc_lock", "nightly"] } prettytable = "0.10.0" proctitle = "0.1.1" -rdkafka = { version = "0.32.2", features = ["tracing"] } +rdkafka = { version = "0.33.0", features = ["tracing"] } regex = "1.8.4" reqwest = { version = "0.11.18", default-features = false, features = ["deflate", "gzip", "json", "tokio-rustls"] } rmp-serde = "1.1.1" @@ -93,7 +93,7 @@ serde = { version = "1.0.164" } serde_json = { version = "1.0.99", default-features = false, features = ["raw_value"] } serde_prometheus = "0.2.3" strum = { version = "0.25.0", features = ["derive"] } -time_01 = { package = "time", version = "0.1" } +time_01 = { package = "time", version = "0.1.45" } time_03 = { package = "time", version = "0.3" } tokio = { version = "1.29.1", features = ["full", "tracing"] } tokio-console = { version = "0.1.8", optional = true } From b13e5b24407fc328d60e7d728d898caf22d36e0e Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 12:17:30 -0700 Subject: [PATCH 05/11] move more logs to tracing and possible stripe payment fix maybe RawValue does need to_string instead of just get --- web3_proxy/src/errors.rs | 34 +++++--- .../src/frontend/users/payment_stripe.rs | 77 ++++++------------- 2 files changed, 48 insertions(+), 63 deletions(-) diff --git a/web3_proxy/src/errors.rs b/web3_proxy/src/errors.rs index 5df1a75c..302eb4b0 100644 --- a/web3_proxy/src/errors.rs +++ b/web3_proxy/src/errors.rs @@ -146,6 +146,7 @@ pub enum Web3ProxyError { /// simple way to return an error message to the user and an anyhow to our logs #[display(fmt = "{}, {}, {:?}", _0, _1, _2)] StatusCode(StatusCode, Cow<'static, str>, Option), + StripeWebhookError(stripe::WebhookError), /// TODO: what should be attached to the timout? #[display(fmt = "{:?}", _0)] #[error(ignore)] @@ -498,7 +499,7 @@ impl Web3ProxyError { StatusCode::INTERNAL_SERVER_ERROR, JsonRpcErrorData { // TODO: is it safe to expose our io error strings? - message: err.to_string().into(), + message: format!("std io error: {}", err).into(), code: StatusCode::INTERNAL_SERVER_ERROR.as_u16().into(), data: None, }, @@ -674,7 +675,7 @@ impl Web3ProxyError { num_known, min_head_rpcs, } => { - error!("NotEnoughRpcs {}/{}", num_known, min_head_rpcs); + error!(%num_known, %min_head_rpcs, "NotEnoughRpcs"); ( StatusCode::BAD_GATEWAY, JsonRpcErrorData { @@ -689,7 +690,7 @@ impl Web3ProxyError { ) } Self::NotEnoughSoftLimit { available, needed } => { - error!("NotEnoughSoftLimit {}/{}", available, needed); + error!(available, needed, "NotEnoughSoftLimit"); ( StatusCode::BAD_GATEWAY, JsonRpcErrorData { @@ -742,7 +743,7 @@ impl Web3ProxyError { ) } Self::OriginNotAllowed(origin) => { - trace!("OriginNotAllowed origin={}", origin); + trace!(?origin, "OriginNotAllowed"); ( StatusCode::FORBIDDEN, JsonRpcErrorData { @@ -753,7 +754,7 @@ impl Web3ProxyError { ) } Self::ParseBytesError(err) => { - trace!("ParseBytesError err={:#?}", err); + trace!(?err, "ParseBytesError"); ( StatusCode::BAD_REQUEST, JsonRpcErrorData { @@ -764,7 +765,7 @@ impl Web3ProxyError { ) } Self::ParseMsgError(err) => { - trace!("ParseMsgError err={:#?}", err); + trace!(?err, "ParseMsgError"); ( StatusCode::BAD_REQUEST, JsonRpcErrorData { @@ -936,9 +937,22 @@ impl Web3ProxyError { }, ) } + Self::StripeWebhookError(err) => { + trace!(?err, "StripeWebhookError"); + ( + StatusCode::BAD_REQUEST, + JsonRpcErrorData { + message: format!("stripe webhook error: {}", err).into(), + code: StatusCode::BAD_REQUEST.as_u16().into(), + // TODO: include the stripe signature? anything else? + data: None, + }, + ) + } Self::Timeout(x) => ( StatusCode::REQUEST_TIMEOUT, JsonRpcErrorData { + // TODO: prettier message message: format!("request timed out: {:?}", x).into(), code: StatusCode::REQUEST_TIMEOUT.as_u16().into(), // TODO: include the actual id! @@ -946,11 +960,11 @@ impl Web3ProxyError { }, ), Self::UlidDecode(err) => { - // trace!(?err, "UlidDecodeError"); + trace!(?err, "UlidDecodeError"); ( StatusCode::BAD_REQUEST, JsonRpcErrorData { - message: format!("{}", err).into(), + message: format!("ulid decode error: {}", err).into(), code: StatusCode::BAD_REQUEST.as_u16().into(), data: None, }, @@ -1010,7 +1024,7 @@ impl Web3ProxyError { ) } Self::UserAgentNotAllowed(ua) => { - trace!("UserAgentNotAllowed ua={}", ua); + trace!(%ua, "UserAgentNotAllowed"); ( StatusCode::FORBIDDEN, JsonRpcErrorData { @@ -1033,7 +1047,7 @@ impl Web3ProxyError { ) } Self::WatchRecvError(err) => { - error!("WatchRecvError err={:#?}", err); + error!(?err, "WatchRecvError"); ( StatusCode::INTERNAL_SERVER_ERROR, JsonRpcErrorData { diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs index 35a0a29f..00dcd92d 100644 --- a/web3_proxy/src/frontend/users/payment_stripe.rs +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -1,15 +1,11 @@ use crate::app::Web3ProxyApp; use crate::errors::{Web3ProxyError, Web3ProxyErrorContext, Web3ProxyResponse}; -use crate::frontend::authorization::{ - login_is_authorized, Authorization as Web3ProxyAuthorization, -}; use anyhow::Context; use axum::{ headers::{authorization::Bearer, Authorization}, response::IntoResponse, Extension, Json, TypedHeader, }; -use axum_client_ip::InsecureClientIp; use axum_macros::debug_handler; use entities::{ balance, increase_on_chain_balance_receipt, rpc_key, stripe_increase_balance_receipt, user, @@ -21,12 +17,12 @@ use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, TransactionTrait, }; use migration::{Expr, OnConflict}; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use serde_json::json; use std::num::NonZeroU64; use std::sync::Arc; use stripe::Webhook; -use tracing::{debug, error, trace}; +use tracing::{error, info, trace}; /// `GET /user/balance/stripe` -- Use a bearer token to get the user's balance and spend. /// @@ -55,12 +51,9 @@ pub async fn user_stripe_deposits_get( Ok(Json(response).into_response()) } -// /// the JSON input to the `post_user` handler. -// /// TODO: what else can we update here? password hash? subscription to newsletter? -#[derive(Debug, Serialize, Deserialize)] +/// the JSON input to the `user_balance_stripe_post` handler. +#[derive(Debug, Deserialize)] pub struct StripePost { - // email: Option, - // referral_code: Option, data: Box, } @@ -69,38 +62,18 @@ pub struct StripePost { #[debug_handler] pub async fn user_balance_stripe_post( Extension(app): Extension>, - InsecureClientIp(ip): InsecureClientIp, + // InsecureClientIp(ip): InsecureClientIp, headers: HeaderMap, - bearer: Option>>, Json(payload): Json, ) -> Web3ProxyResponse { - // rate limit by bearer token **OR** IP address - let (_, _semaphore) = if let Some(TypedHeader(Authorization(bearer))) = bearer { - let (_, semaphore) = app.bearer_is_authorized(bearer).await?; + // TODO: (high) rate limits by IP address. login limiter is probably too low + // TODO: maybe instead, a bad stripe-header should ban the IP? or a good one should allow it? - // TODO: is handling this as internal fine? - let authorization = Web3ProxyAuthorization::internal(app.db_conn().ok().cloned())?; + // TODO: lower log level when done testing + info!(?payload, ?headers); - (authorization, Some(semaphore)) - } else { - let authorization = login_is_authorized(&app, ip).await?; - (authorization, None) - }; - - // let recipient_user_id: u64 = params - // .remove("user_id") - // .ok_or(Web3ProxyError::BadRouting)? - // .parse() - // .or(Err(Web3ProxyError::ParseAddressError))?; - - trace!(?payload); - - // Get the payload, and the header - // let payload = payload.data.get("data").ok_or(Web3ProxyError::BadRequest( - // "You have not provided a 'data' for the Stripe payload".into(), - // ))?; - - // TODO Get this from the header + // get the signature from the header + // the docs are inconsistent on the key, so we just check all of them let signature = if let Some(x) = headers.get("stripe-signature") { x } else if let Some(x) = headers.get("Stripe-Signature") { @@ -115,30 +88,28 @@ pub async fn user_balance_stripe_post( )); }; + let payload = + serde_json::to_string(&payload.data).web3_context("could not parse payload data")?; + let signature = signature .to_str() .web3_context("Could not parse stripe signature as byte-string")?; - // Now parse the payload and signature - // TODO: Move env variable elsewhere - let event = Webhook::construct_event( - payload.data.get(), - signature, - app.config - .stripe_api_key - .clone() - .web3_context("Stripe API key not found in config!")? - .as_str(), - ) - .context(Web3ProxyError::BadRequest( - "Could not parse the stripe webhook request!".into(), - ))?; + let secret = app + .config + .stripe_api_key + .clone() + .web3_context("Stripe API key not found in config!")?; + + let event = Webhook::construct_event(&payload, signature, secret.as_str())?; let intent = match event.data.object { stripe::EventObject::PaymentIntent(intent) => intent, _ => return Ok("Received irrelevant webhook".into_response()), }; - debug!("Found PaymentIntent Event: {:?}", intent); + + // TODO: lower log level when done testing + info!(?intent); if intent.status.as_str() != "succeeded" { return Ok("Received Webhook".into_response()); From 64505953ee91c416510fe2fe4df9ac570c549c49 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 12:28:07 -0700 Subject: [PATCH 06/11] cargo upgrade --- Cargo.lock | 58 +++++++++++++++++++++---------------------- entities/Cargo.toml | 2 +- latency/Cargo.toml | 2 +- web3_proxy/Cargo.toml | 4 +-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce118b79..1154653c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -289,7 +289,7 @@ checksum = "0e97ce7de6cf12de5d7226c73f5ba9811622f4db3a5b91b55c53e987e5f91cba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -377,7 +377,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -413,13 +413,13 @@ checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "7b2d0f03b3640e3a630367e40c468cb7f309529c708ed1d88597047b0e7c6ef7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -561,7 +561,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -1884,7 +1884,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.22", + "syn 2.0.23", "toml 0.7.5", "walkdir", ] @@ -1902,7 +1902,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -1928,7 +1928,7 @@ dependencies = [ "serde", "serde_json", "strum 0.24.1", - "syn 2.0.22", + "syn 2.0.23", "tempfile", "thiserror", "tiny-keccak", @@ -2347,7 +2347,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -3659,7 +3659,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -3731,7 +3731,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -4018,7 +4018,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -4082,7 +4082,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -4120,7 +4120,7 @@ checksum = "d1fef411b303e3e12d534fb6e7852de82da56edd937d895125821fb7c09436c7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -4214,7 +4214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" dependencies = [ "proc-macro2", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -5460,22 +5460,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.164" +version = "1.0.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -6038,7 +6038,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -6080,9 +6080,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.22" +version = "2.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" dependencies = [ "proc-macro2", "quote", @@ -6175,7 +6175,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -6330,7 +6330,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -6586,7 +6586,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", ] [[package]] @@ -7005,7 +7005,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", "wasm-bindgen-shared", ] @@ -7039,7 +7039,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.23", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/entities/Cargo.toml b/entities/Cargo.toml index 0973391b..eb218433 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -12,6 +12,6 @@ path = "src/mod.rs" [dependencies] ethers = { version = "2.0.7", default-features = false } sea-orm = "0.11.3" -serde = "1.0.164" +serde = "1.0.166" ulid = "1.0.0" uuid = "1.4.0" diff --git a/latency/Cargo.toml b/latency/Cargo.toml index ea391447..a9d36f96 100644 --- a/latency/Cargo.toml +++ b/latency/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" flume = "0.10.14" log = "0.4.19" portable-atomic = { version = "1.3.3", features = ["float"] } -serde = { version = "1.0.164", features = [] } +serde = { version = "1.0.166", features = [] } tokio = { version = "1.29.1", features = ["full"] } tracing = "0.1.37" watermill = "0.1.1" diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index f26b78c7..03fecd03 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -44,7 +44,7 @@ anyhow = { version = "1.0.71", features = ["backtrace"] } arc-swap = { version = "1.6.0" } argh = "0.1.10" async-stripe = { version = "0.22.2", default-features = false, features = ["full", "runtime-tokio-hyper-rustls", "webhook-events"] } -async-trait = "0.1.68" +async-trait = "0.1.69" axum = { version = "0.6.18", features = ["headers", "tracing", "ws"] } axum-client-ip = "0.4.1" axum-macros = "0.3.7" @@ -89,7 +89,7 @@ rmp-serde = "1.1.1" rust_decimal = { version = "1.30.0", features = ["maths"] } sentry = { version = "0.31.5", default-features = false, features = ["anyhow", "backtrace", "contexts", "panic", "reqwest", "rustls", "serde_json", "tracing"] } sentry-tracing = "0.31.5" -serde = { version = "1.0.164" } +serde = { version = "1.0.166" } serde_json = { version = "1.0.99", default-features = false, features = ["raw_value"] } serde_prometheus = "0.2.3" strum = { version = "0.25.0", features = ["derive"] } From d8512d50de6cb0c71aba22251f5c3027c3ed7856 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 12:57:48 -0700 Subject: [PATCH 07/11] just pass the whole string through based on this test (which i think async-stripe forked): https://docs.rs/stripe-rust/0.12.3/src/stripe/resources/event.rs.html#355 and then based on the struct that they deserialize into: https://docs.rs/async-stripe/latest/src/stripe/resources/generated/event.rs.html#16 --- web3_proxy/src/frontend/users/payment_stripe.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs index 00dcd92d..27989071 100644 --- a/web3_proxy/src/frontend/users/payment_stripe.rs +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -51,12 +51,6 @@ pub async fn user_stripe_deposits_get( Ok(Json(response).into_response()) } -/// the JSON input to the `user_balance_stripe_post` handler. -#[derive(Debug, Deserialize)] -pub struct StripePost { - data: Box, -} - /// `POST /user/balance/stripe` -- Process a stripe transaction; /// this endpoint is called from the webhook with the user_id parameter in the request #[debug_handler] @@ -64,7 +58,7 @@ pub async fn user_balance_stripe_post( Extension(app): Extension>, // InsecureClientIp(ip): InsecureClientIp, headers: HeaderMap, - Json(payload): Json, + payload: String, ) -> Web3ProxyResponse { // TODO: (high) rate limits by IP address. login limiter is probably too low // TODO: maybe instead, a bad stripe-header should ban the IP? or a good one should allow it? @@ -88,9 +82,6 @@ pub async fn user_balance_stripe_post( )); }; - let payload = - serde_json::to_string(&payload.data).web3_context("could not parse payload data")?; - let signature = signature .to_str() .web3_context("Could not parse stripe signature as byte-string")?; From 8c8080e01d293714ee2c427b265e5070226c85b1 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 13:12:12 -0700 Subject: [PATCH 08/11] less async-stripe features --- web3_proxy/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 03fecd03..146414c7 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -43,7 +43,7 @@ siwe = { git = "https://github.com/llamanodes/siwe-rs", rev = "013be5204ff1c8577 anyhow = { version = "1.0.71", features = ["backtrace"] } arc-swap = { version = "1.6.0" } argh = "0.1.10" -async-stripe = { version = "0.22.2", default-features = false, features = ["full", "runtime-tokio-hyper-rustls", "webhook-events"] } +async-stripe = { version = "0.22.2", default-features = false, features = ["billing", "checkout", "connect", "runtime-tokio-hyper-rustls", "webhook-events"] } async-trait = "0.1.69" axum = { version = "0.6.18", features = ["headers", "tracing", "ws"] } axum-client-ip = "0.4.1" From d9c6da74c29562c13a0f19041e433b1b950009dc Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 13:30:37 -0700 Subject: [PATCH 09/11] fix case on currency check --- web3_proxy/src/frontend/users/payment_stripe.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs index 27989071..b365e619 100644 --- a/web3_proxy/src/frontend/users/payment_stripe.rs +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -152,7 +152,7 @@ pub async fn user_balance_stripe_post( let txn = db_conn.begin().await?; // Assert that it's usd - if intent.currency.to_string() != "USD" || recipient.is_none() { + if intent.currency.to_string() != "usd" || recipient.is_none() { // In this case I should probably still save it to the database, // but not increase balance (this should be refunded) // TODO: I suppose we could send a refund request right away from here From ee6b725a1b616887caf7a1457e33c6912c9ba92b Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 13:34:16 -0700 Subject: [PATCH 10/11] lower log level on payload and headers --- web3_proxy/src/frontend/users/payment_stripe.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs index b365e619..ec1d57fe 100644 --- a/web3_proxy/src/frontend/users/payment_stripe.rs +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -17,12 +17,11 @@ use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, TransactionTrait, }; use migration::{Expr, OnConflict}; -use serde::Deserialize; use serde_json::json; use std::num::NonZeroU64; use std::sync::Arc; use stripe::Webhook; -use tracing::{error, info, trace}; +use tracing::{debug, error, info, trace}; /// `GET /user/balance/stripe` -- Use a bearer token to get the user's balance and spend. /// @@ -64,7 +63,7 @@ pub async fn user_balance_stripe_post( // TODO: maybe instead, a bad stripe-header should ban the IP? or a good one should allow it? // TODO: lower log level when done testing - info!(?payload, ?headers); + debug!(%payload, ?headers); // get the signature from the header // the docs are inconsistent on the key, so we just check all of them From 10bd615f1402a60fd078bfb547191391469055fb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 3 Jul 2023 13:45:59 -0700 Subject: [PATCH 11/11] need to use the display function for the path or it rebuilds every time --- payment-contracts/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payment-contracts/build.rs b/payment-contracts/build.rs index 52a01972..31b876bc 100644 --- a/payment-contracts/build.rs +++ b/payment-contracts/build.rs @@ -5,7 +5,7 @@ fn main() { // Tell Cargo that if the given file changes, to rerun this build script. glob("./abi/*.json").unwrap().for_each(|x| { if let Ok(x) = x { - println!("cargo:rerun-if-changed={:?}", x); + println!("cargo:rerun-if-changed={}", x.display()); } });