Merge remote-tracking branch 'origin/devel' into david/test-admin
This commit is contained in:
commit
d613969c3e
87
Cargo.lock
generated
87
Cargo.lock
generated
@ -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",
|
||||
]
|
||||
@ -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,20 +561,20 @@ dependencies = [
|
||||
"heck 0.4.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[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",
|
||||
]
|
||||
@ -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",
|
||||
@ -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]]
|
||||
@ -2347,7 +2347,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@ -3668,14 +3659,14 @@ dependencies = [
|
||||
"proc-macro-crate 1.3.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[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",
|
||||
]
|
||||
@ -3740,7 +3731,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4027,7 +4018,7 @@ dependencies = [
|
||||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4091,7 +4082,7 @@ dependencies = [
|
||||
"phf_shared 0.11.2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4129,7 +4120,7 @@ checksum = "d1fef411b303e3e12d534fb6e7852de82da56edd937d895125821fb7c09436c7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4223,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]]
|
||||
@ -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",
|
||||
@ -5469,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]]
|
||||
@ -6047,7 +6038,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -6089,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",
|
||||
@ -6184,7 +6175,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -6339,7 +6330,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -6595,7 +6586,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -7014,7 +7005,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@ -7048,7 +7039,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.22",
|
||||
"syn 2.0.23",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -43,8 +43,8 @@ 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-trait = "0.1.68"
|
||||
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"
|
||||
axum-macros = "0.3.7"
|
||||
@ -82,18 +82,18 @@ 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"
|
||||
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"] }
|
||||
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 }
|
||||
|
@ -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<anyhow::Error>),
|
||||
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 {
|
||||
|
@ -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,11 @@ use migration::sea_orm::{
|
||||
self, ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, TransactionTrait,
|
||||
};
|
||||
use migration::{Expr, OnConflict};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use std::num::NonZeroU64;
|
||||
use std::sync::Arc;
|
||||
use stripe::Webhook;
|
||||
use tracing::{debug, error, trace};
|
||||
use tracing::{debug, error, info, trace};
|
||||
|
||||
/// `GET /user/balance/stripe` -- Use a bearer token to get the user's balance and spend.
|
||||
///
|
||||
@ -55,80 +50,56 @@ 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)]
|
||||
pub struct StripePost {
|
||||
// email: Option<String>,
|
||||
// referral_code: Option<String>,
|
||||
data: Box<serde_json::value::RawValue>,
|
||||
}
|
||||
|
||||
/// `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]
|
||||
pub async fn user_balance_stripe_post(
|
||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||
InsecureClientIp(ip): InsecureClientIp,
|
||||
// InsecureClientIp(ip): InsecureClientIp,
|
||||
headers: HeaderMap,
|
||||
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
||||
Json(payload): Json<StripePost>,
|
||||
payload: String,
|
||||
) -> 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
|
||||
debug!(%payload, ?headers);
|
||||
|
||||
(authorization, Some(semaphore))
|
||||
// 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") {
|
||||
x
|
||||
} else if let Some(x) = headers.get("STRIPE_SIGNATURE") {
|
||||
x
|
||||
} else if let Some(x) = headers.get("HTTP_STRIPE_SIGNATURE") {
|
||||
x
|
||||
} else {
|
||||
let authorization = login_is_authorized(&app, ip).await?;
|
||||
(authorization, None)
|
||||
return Err(Web3ProxyError::BadRequest(
|
||||
"You have not provided a 'STRIPE_SIGNATURE' for the Stripe payload".into(),
|
||||
));
|
||||
};
|
||||
|
||||
// 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
|
||||
let signature = headers
|
||||
.get("STRIPE_SIGNATURE")
|
||||
.ok_or(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")?;
|
||||
|
||||
// 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());
|
||||
@ -180,7 +151,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
|
||||
|
@ -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() {
|
||||
|
@ -1,14 +1,21 @@
|
||||
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::{LoginPostResponse, PostLogin};
|
||||
use web3_proxy::frontend::users::authentication::PostLogin;
|
||||
|
||||
/// TODO: use this type in the frontend
|
||||
#[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<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
/// TODO: 191 and the other message formats in another test
|
||||
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
||||
|
Loading…
Reference in New Issue
Block a user