diff --git a/.env b/.env index e9f9714b..c0b01f45 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ DATABASE_URL=mysql://root:dev_web3_proxy@127.0.0.1:13306/dev_web3_proxy +STRIPE_API_KEY= \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 97cd40f8..a726474b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,9 +29,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aes" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241" +checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" dependencies = [ "cfg-if", "cipher", @@ -44,7 +44,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom", + "getrandom 0.2.10", "once_cell", "version_check", ] @@ -77,9 +77,9 @@ checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" [[package]] name = "allocator-api2" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f263788a35611fba42eb41ff811c5d0360c58b97402570312a350736e2542e" +checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9" [[package]] name = "android-tzdata" @@ -150,9 +150,9 @@ checksum = "64cb94155d965e3d37ffbbe7cc5b82c3dd79dd33bd48e536f73d2cfb8d85506f" [[package]] name = "arrayvec" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8868f09ff8cea88b079da74ae569d9b8c62a23c68c746240b704ee6f7525c89c" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "ascii-canvas" @@ -380,6 +380,32 @@ dependencies = [ "syn 2.0.22", ] +[[package]] +name = "async-stripe" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b313de0d654c4c4c46faa737b2257ce9ed79e69926aa4c734b9816be20102b2c" +dependencies = [ + "chrono", + "futures-util", + "hex", + "hmac", + "http-types", + "hyper", + "hyper-rustls 0.23.2", + "serde", + "serde_json", + "serde_path_to_error", + "serde_qs 0.10.1", + "sha2 0.10.7", + "smart-default", + "smol_str", + "thiserror", + "time-core", + "tokio", + "uuid 0.8.2", +] + [[package]] name = "async-task" version = "4.4.0" @@ -640,9 +666,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbe3c979c178231552ecba20214a8272df4e09f232a87aef4320cf06539aded" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" [[package]] name = "bitvec" @@ -914,7 +940,7 @@ dependencies = [ "async-std-resolver", "log", "mailchecker", - "rand", + "rand 0.8.5", "reacher-fast-socks5", "regex", "reqwest", @@ -1016,12 +1042,12 @@ dependencies = [ "bs58", "coins-core", "digest 0.10.7", - "getrandom", + "getrandom 0.2.10", "hmac", "k256", "lazy_static", "serde", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", ] @@ -1033,12 +1059,12 @@ checksum = "84f4d04ee18e58356accd644896aeb2094ddeafb6a713e056cef0c0a8e468c15" dependencies = [ "bitvec 0.17.4", "coins-bip32", - "getrandom", + "getrandom 0.2.10", "hmac", "once_cell", "pbkdf2 0.12.1", - "rand", - "sha2 0.10.6", + "rand 0.8.5", + "sha2 0.10.7", "thiserror", ] @@ -1057,7 +1083,7 @@ dependencies = [ "ripemd", "serde", "serde_derive", - "sha2 0.10.6", + "sha2 0.10.7", "sha3", "thiserror", ] @@ -1158,9 +1184,9 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "const-oid" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +checksum = "6340df57935414636969091153f35f68d9f00bbc8fb4a9c6054706c213e6c6bc" [[package]] name = "constant_time_eq" @@ -1201,9 +1227,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" dependencies = [ "libc", ] @@ -1325,7 +1351,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" dependencies = [ "generic-array", - "rand_core", + "rand_core 0.6.4", "subtle", "zeroize", ] @@ -1447,11 +1473,11 @@ dependencies = [ [[package]] name = "der" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56acb310e15652100da43d130af8d97b509e95af61aab1c5a7939ef24337ee17" +checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" dependencies = [ - "const-oid 0.9.2", + "const-oid 0.9.3", "zeroize", ] @@ -1501,7 +1527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid 0.9.2", + "const-oid 0.9.3", "crypto-common", "subtle", ] @@ -1577,7 +1603,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" dependencies = [ - "der 0.7.6", + "der 0.7.7", "digest 0.10.7", "elliptic-curve", "rfc6979", @@ -1604,7 +1630,7 @@ dependencies = [ "generic-array", "group", "pkcs8 0.10.2", - "rand_core", + "rand_core 0.6.4", "sec1", "subtle", "zeroize", @@ -1645,7 +1671,7 @@ dependencies = [ "hex", "k256", "log", - "rand", + "rand 0.8.5", "rlp", "serde", "sha3", @@ -1737,11 +1763,11 @@ dependencies = [ "hex", "hmac", "pbkdf2 0.11.0", - "rand", + "rand 0.8.5", "scrypt", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.7", "sha3", "thiserror", "uuid 0.8.2", @@ -1900,7 +1926,7 @@ dependencies = [ "num_enum 0.6.1", "once_cell", "open-fastrlp", - "rand", + "rand 0.8.5", "rlp", "serde", "serde_json", @@ -2004,8 +2030,8 @@ dependencies = [ "eth-keystore", "ethers-core", "hex", - "rand", - "sha2 0.10.6", + "rand 0.8.5", + "sha2 0.10.7", "thiserror", "tracing", ] @@ -2109,7 +2135,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -2120,7 +2146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "byteorder", - "rand", + "rand 0.8.5", "rustc-hex", "static_assertions", ] @@ -2387,6 +2413,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -2437,15 +2474,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core", + "rand_core 0.6.4", "subtle", ] [[package]] name = "h2" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782" +checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" dependencies = [ "bytes", "fnv", @@ -2609,15 +2646,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.1" @@ -2687,6 +2715,27 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" +[[package]] +name = "http-types" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9b187a72d63adbfba487f48095306ac823049cb504ee195541e91c7775f5ad" +dependencies = [ + "anyhow", + "async-channel", + "base64 0.13.1", + "futures-lite", + "http", + "infer", + "pin-project-lite", + "rand 0.7.3", + "serde", + "serde_json", + "serde_qs 0.8.5", + "serde_urlencoded", + "url", +] + [[package]] name = "httparse" version = "1.8.0" @@ -2729,6 +2778,21 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +dependencies = [ + "http", + "hyper", + "log", + "rustls 0.20.8", + "rustls-native-certs", + "tokio", + "tokio-rustls 0.23.4", +] + [[package]] name = "hyper-rustls" version = "0.24.0" @@ -2875,6 +2939,12 @@ dependencies = [ "hashbrown 0.14.0", ] +[[package]] +name = "infer" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e9829a50b42bb782c1df523f78d332fe371b10c661e78b7a3c34b0198e9fac" + [[package]] name = "influxdb2" version = "0.4.2" @@ -2894,7 +2964,7 @@ dependencies = [ "secrecy", "serde", "serde_json", - "serde_qs", + "serde_qs 0.12.0", "snafu", "tempfile", "tracing", @@ -3058,7 +3128,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.6", + "sha2 0.10.7", "signature", ] @@ -3398,7 +3468,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -3487,9 +3557,9 @@ dependencies = [ [[package]] name = "num-bigint-dig" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2399c9463abc5f909349d8aa9ba080e0b88b3ce2885389b60b993f39b1a56905" +checksum = "53ba502077159ace3aa56c25449a007173a406607a94ef665247246191eb38b1" dependencies = [ "byteorder", "lazy_static", @@ -3497,7 +3567,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand", + "rand 0.8.5", "smallvec", "zeroize", ] @@ -3556,11 +3626,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.1", "libc", ] @@ -3654,9 +3724,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.54" +version = "0.10.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b3f656a17a6cbc115b5c7a40c616947d213ba182135b014d6051b73ab6f019" +checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" dependencies = [ "bitflags 1.3.2", "cfg-if", @@ -3686,18 +3756,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "111.25.3+1.1.1t" +version = "111.26.0+1.1.1u" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "924757a6a226bf60da5f7dd0311a34d2b52283dd82ddeb103208ddc66362f80c" +checksum = "efc62c9f12b22b8f5208c23a7200a442b2e5999f8bdf80233852122b5a4f6f37" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.88" +version = "0.9.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ce0f250f34a308dcfdbb351f511359857d4ed2134ba715a4eadd46e1ffd617" +checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" dependencies = [ "cc", "libc", @@ -3713,7 +3783,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fc2dbde8f8a79f2102cc474ceb0ad68e3b80b85289ea62389b60e66777e4213" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", "serde", ] @@ -3777,15 +3847,15 @@ checksum = "bd10bab2b6df910bbe6c4987d76aa4221235103d9a9c000cfabcee6a6abc8f7a" dependencies = [ "reqwest", "serde", - "time 0.3.22", + "time 0.3.20", "url", ] [[package]] name = "parity-scale-codec" -version = "3.5.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ddb756ca205bd108aee3c62c6d3c994e1df84a59b9d6d4a5ea42ee1fd5a9a28" +checksum = "2287753623c76f953acd29d15d8100bcab84d29db78fb6f352adb3c53e83b967" dependencies = [ "arrayvec", "bitvec 1.0.1", @@ -3797,9 +3867,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.1.4" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b" +checksum = "2b6937b5e67bfba3351b87b040d48352a2fcb6ad72f81855412ce97b45c8f110" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -3871,7 +3941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -3905,7 +3975,7 @@ dependencies = [ "digest 0.10.7", "hmac", "password-hash", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] @@ -3935,9 +4005,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pest" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68e84bfb01f0507134eac1e9b410a12ba379d064eab48c50ba4ce329a527b70" +checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" dependencies = [ "thiserror", "ucd-trie", @@ -3945,9 +4015,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b79d4c71c865a25a4322296122e3924d30bc8ee0834c8bfc8b95f7f054afbfb" +checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" dependencies = [ "pest", "pest_generator", @@ -3955,9 +4025,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c435bf1076437b851ebc8edc3a18442796b30f1728ffea6262d59bbe28b077e" +checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" dependencies = [ "pest", "pest_meta", @@ -3968,13 +4038,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745a452f8eb71e39ffd8ee32b3c5f51d03845f99786fa9b68db6ff509c505411" +checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" dependencies = [ "once_cell", "pest", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] @@ -3999,35 +4069,35 @@ dependencies = [ [[package]] name = "phf" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_macros", - "phf_shared 0.11.1", + "phf_shared 0.11.2", ] [[package]] name = "phf_generator" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ - "phf_shared 0.11.1", - "rand", + "phf_shared 0.11.2", + "rand 0.8.5", ] [[package]] name = "phf_macros" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92aacdc5f16768709a569e913f7451034034178b05bdc8acda226659a3dccc66" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ "phf_generator", - "phf_shared 0.11.1", + "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.22", ] [[package]] @@ -4041,27 +4111,27 @@ dependencies = [ [[package]] name = "phf_shared" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", ] [[package]] name = "pin-project" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" +checksum = "6e138fdd8263907a2b0e1b4e80b7e58c721126479b6e6eedfb1b402acea7b9bd" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" +checksum = "d1fef411b303e3e12d534fb6e7852de82da56edd937d895125821fb7c09436c7" dependencies = [ "proc-macro2", "quote", @@ -4108,7 +4178,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.6", + "der 0.7.7", "spki 0.7.2", ] @@ -4154,9 +4224,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b69d39aab54d069e7f2fe8cb970493e7834601ca2d8c65fd7bbd183578080d1" +checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" dependencies = [ "proc-macro2", "syn 2.0.22", @@ -4346,9 +4416,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.28" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" dependencies = [ "proc-macro2", ] @@ -4365,6 +4435,19 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -4372,11 +4455,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", "serde", ] +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -4384,7 +4477,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", ] [[package]] @@ -4393,10 +4495,19 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.10", "serde", ] +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "rate-counter" version = "0.1.0" @@ -4537,7 +4648,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom", + "getrandom 0.2.10", "redox_syscall 0.2.16", "thiserror", ] @@ -4599,7 +4710,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls", + "hyper-rustls 0.24.0", "hyper-tls", "ipnet", "js-sys", @@ -4774,7 +4885,7 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8 0.8.0", - "rand_core", + "rand_core 0.6.4", "smallvec", "subtle", "zeroize", @@ -4792,7 +4903,7 @@ dependencies = [ "byteorder", "bytes", "num-traits", - "rand", + "rand 0.8.5", "rkyv", "serde", "serde_json", @@ -4858,10 +4969,22 @@ dependencies = [ ] [[package]] -name = "rustls-pemfile" -version = "1.0.2" +name = "rustls-native-certs" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ "base64 0.21.2", ] @@ -4908,9 +5031,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b569c32c806ec3abdf3b5869fb8bf1e0d275a7c1c9b0b05603d9464632649edf" +checksum = "ad560913365790f17cbf12479491169f01b9d46d29cfc7422bf8c64bdc61b731" dependencies = [ "cfg-if", "derive_more", @@ -4920,9 +5043,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.6.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53012eae69e5aa5c14671942a5dd47de59d4cdcff8532a6dd0e081faf1119482" +checksum = "19df9bd9ace6cc2fe19387c96ce677e823e07d017ceed253e7bb3d1d1bd9c73b" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -4993,7 +5116,7 @@ dependencies = [ "hmac", "pbkdf2 0.11.0", "salsa20", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] @@ -5028,7 +5151,7 @@ dependencies = [ "serde_json", "sqlx", "thiserror", - "time 0.3.22", + "time 0.3.20", "tracing", "url", "uuid 1.4.0", @@ -5091,7 +5214,7 @@ dependencies = [ "rust_decimal", "sea-query-derive", "serde_json", - "time 0.3.22", + "time 0.3.20", "uuid 1.4.0", ] @@ -5107,7 +5230,7 @@ dependencies = [ "sea-query", "serde_json", "sqlx", - "time 0.3.22", + "time 0.3.20", "uuid 1.4.0", ] @@ -5182,7 +5305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" dependencies = [ "base16ct", - "der 0.7.6", + "der 0.7.7", "generic-array", "pkcs8 0.10.2", "subtle", @@ -5307,7 +5430,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7163491708804a74446642ff2c80b3acd668d4b9e9f497f85621f3d250fd012b" dependencies = [ "once_cell", - "rand", + "rand 0.8.5", "sentry-types", "serde", "serde_json", @@ -5342,12 +5465,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e7a88e0c1922d19b3efee12a8215f6a8a806e442e665ada71cc222cab72985f" dependencies = [ "debugid", - "getrandom", + "getrandom 0.2.10", "hex", "serde", "serde_json", "thiserror", - "time 0.3.22", + "time 0.3.20", "url", "uuid 1.4.0", ] @@ -5426,6 +5549,28 @@ dependencies = [ "thiserror", ] +[[package]] +name = "serde_qs" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7715380eec75f029a4ef7de39a9200e0a63823176b759d055b613f5a87df6a6" +dependencies = [ + "percent-encoding", + "serde", + "thiserror", +] + +[[package]] +name = "serde_qs" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cac3f1e2ca2fe333923a1ae72caca910b98ed0630bb35ef6f8c8517d6e81afa" +dependencies = [ + "percent-encoding", + "serde", + "thiserror", +] + [[package]] name = "serde_qs" version = "0.12.0" @@ -5484,9 +5629,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", @@ -5549,7 +5694,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ "digest 0.10.7", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -5574,11 +5719,11 @@ dependencies = [ "http", "iri-string", "k256", - "rand", + "rand 0.8.5", "serde", "sha3", "thiserror", - "time 0.3.22", + "time 0.3.20", ] [[package]] @@ -5611,6 +5756,26 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "smart-default" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "smol_str" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9" +dependencies = [ + "serde", +] + [[package]] name = "snafu" version = "0.7.4" @@ -5699,7 +5864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" dependencies = [ "base64ct", - "der 0.7.6", + "der 0.7.7", ] [[package]] @@ -5757,7 +5922,7 @@ dependencies = [ "once_cell", "paste", "percent-encoding", - "rand", + "rand 0.8.5", "rsa", "rust_decimal", "rustls 0.20.8", @@ -5765,13 +5930,13 @@ dependencies = [ "serde", "serde_json", "sha1", - "sha2 0.10.6", + "sha2 0.10.7", "smallvec", "sqlformat", "sqlx-rt", "stringprep", "thiserror", - "time 0.3.22", + "time 0.3.20", "tokio-stream", "url", "uuid 1.4.0", @@ -5913,7 +6078,7 @@ dependencies = [ "semver", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.7", "thiserror", "url", "zip", @@ -6064,9 +6229,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.22" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" dependencies = [ "itoa", "serde", @@ -6076,15 +6241,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" dependencies = [ "time-core", ] @@ -6377,7 +6542,7 @@ dependencies = [ "indexmap 1.9.3", "pin-project", "pin-project-lite", - "rand", + "rand 0.8.5", "slab", "tokio", "tokio-util", @@ -6392,7 +6557,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8bd22a874a2d0b70452d5597b12c537331d49060824a95f49f108994f94aa4c" dependencies = [ - "bitflags 2.3.2", + "bitflags 2.3.3", "bytes", "futures-core", "futures-util", @@ -6524,7 +6689,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand", + "rand 0.8.5", "smallvec", "thiserror", "tinyvec", @@ -6582,7 +6747,7 @@ dependencies = [ "http", "httparse", "log", - "rand", + "rand 0.8.5", "sha1", "thiserror", "url", @@ -6601,7 +6766,7 @@ dependencies = [ "http", "httparse", "log", - "rand", + "rand 0.8.5", "rustls 0.21.2", "sha1", "thiserror", @@ -6640,7 +6805,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13a3aaa69b04e5b66cc27309710a569ea23593612387d67daaf102e73aa974fd" dependencies = [ - "rand", + "rand 0.8.5", "serde", "uuid 1.4.0", ] @@ -6716,9 +6881,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "ureq" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4b45063f47caea744e48f5baa99169bd8bd9b882d80a99941141327bbb00f99" +checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9" dependencies = [ "base64 0.21.2", "log", @@ -6753,7 +6918,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom", + "getrandom 0.2.10", "serde", ] @@ -6763,8 +6928,8 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" dependencies = [ - "getrandom", - "rand", + "getrandom 0.2.10", + "rand 0.8.5", "serde", "zerocopy", ] @@ -6777,9 +6942,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4d330786735ea358f3bc09eea4caa098569c1c93f342d9aca0514915022fe7e" +checksum = "d92ccd67fb88503048c01b59152a04effd0782d035a83a6d256ce6085f08f4a3" [[package]] name = "vcpkg" @@ -6818,6 +6983,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -6938,6 +7109,7 @@ dependencies = [ "anyhow", "arc-swap", "argh", + "async-stripe", "async-trait", "axum", "axum-client-ip", @@ -6998,7 +7170,8 @@ dependencies = [ "siwe", "strum 0.25.0", "test-log", - "time 0.3.22", + "time 0.1.45", + "time 0.3.20", "tokio", "tokio-console", "tokio-stream", @@ -7114,9 +7287,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ "windows_aarch64_gnullvm 0.48.0", "windows_aarch64_msvc 0.48.0", @@ -7275,7 +7448,7 @@ dependencies = [ "futures-task", "futures-util", "generic-array", - "getrandom", + "getrandom 0.2.10", "hashbrown 0.14.0", "heck 0.4.1", "hyper", @@ -7296,8 +7469,8 @@ dependencies = [ "openssl-sys", "parking_lot 0.12.1", "parking_lot_core 0.9.8", - "rand", - "rand_core", + "rand 0.8.5", + "rand_core 0.6.4", "rdkafka", "rdkafka-sys", "regex", @@ -7311,7 +7484,7 @@ dependencies = [ "serde", "serde_json", "sha1", - "sha2 0.10.6", + "sha2 0.10.7", "sha3", "signal-hook", "spki 0.7.2", @@ -7322,7 +7495,7 @@ dependencies = [ "syn 1.0.109", "syn 2.0.22", "test-log", - "time 0.3.22", + "time 0.3.20", "time-macros", "tokio", "tokio-stream", @@ -7416,7 +7589,7 @@ dependencies = [ "hmac", "pbkdf2 0.11.0", "sha1", - "time 0.3.22", + "time 0.3.20", "zstd", ] diff --git a/config/example.toml b/config/example.toml index 28a4ba96..9c98171a 100644 --- a/config/example.toml +++ b/config/example.toml @@ -47,6 +47,8 @@ redirect_rpc_key_url = "https://llamanodes.com/dashboard/keys?key={{rpc_key_id}} # sentry is optional. it is used for browsing error logs # sentry_url = "https://SENTRY_KEY_A.ingest.sentry.io/SENTRY_KEY_B" +stripe_api_key = "" + # public limits are when no key is used. these are instead grouped by ip # 0 = block all public requests public_max_concurrent_requests = 3 diff --git a/entities/src/mod.rs b/entities/src/mod.rs index 00510fae..b67a973e 100644 --- a/entities/src/mod.rs +++ b/entities/src/mod.rs @@ -18,5 +18,6 @@ pub mod rpc_key; pub mod sea_orm_active_enums; pub mod secondary_user; pub mod serialization; +pub mod stripe_increase_balance_receipt; pub mod user; pub mod user_tier; diff --git a/entities/src/stripe_increase_balance_receipt.rs b/entities/src/stripe_increase_balance_receipt.rs new file mode 100644 index 00000000..b287353a --- /dev/null +++ b/entities/src/stripe_increase_balance_receipt.rs @@ -0,0 +1,39 @@ +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.6 + +use sea_orm::entity::prelude::*; +use serde::Serialize; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)] +#[sea_orm(table_name = "stripe_increase_balance_receipt")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: u64, + pub deposit_to_user_id: Option, + pub stripe_payment_intend_id: String, + #[sea_orm(column_type = "Decimal(Some((20, 10)))")] + pub amount: Decimal, + pub currency: String, + pub status: String, + pub description: Option, + pub date_created: DateTimeUtc, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::DepositToUserId", + to = "super::user::Column::Id", + on_update = "NoAction", + on_delete = "NoAction" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 850aed73..0419e1d2 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -32,6 +32,7 @@ mod m20230607_221917_total_deposits; mod m20230615_221201_handle_payment_uncles; mod m20230618_230611_longer_payload; mod m20230619_172237_default_tracking; +mod m20230622_104142_stripe_deposits; pub struct Migrator; @@ -71,6 +72,7 @@ impl MigratorTrait for Migrator { Box::new(m20230615_221201_handle_payment_uncles::Migration), Box::new(m20230618_230611_longer_payload::Migration), Box::new(m20230619_172237_default_tracking::Migration), + Box::new(m20230622_104142_stripe_deposits::Migration), ] } } diff --git a/migration/src/m20230622_104142_stripe_deposits.rs b/migration/src/m20230622_104142_stripe_deposits.rs new file mode 100644 index 00000000..54ebc6d6 --- /dev/null +++ b/migration/src/m20230622_104142_stripe_deposits.rs @@ -0,0 +1,96 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // Replace the sample below with your own migration scripts + manager + .create_table( + Table::create() + .table(StripeIncreaseBalanceReceipt::Table) + .col( + ColumnDef::new(StripeIncreaseBalanceReceipt::Id) + .big_unsigned() + .not_null() + .auto_increment() + .primary_key(), + ) + .col( + ColumnDef::new(StripeIncreaseBalanceReceipt::StripePaymentIntendId) + .string() + .not_null(), + ) + .col( + // I will not mark this as "not null", so we can track who to refund more easily if needed + ColumnDef::new(StripeIncreaseBalanceReceipt::DepositToUserId) + .big_unsigned(), + ) + .foreign_key( + ForeignKey::create() + .name("fk-stripe_deposits_to_user_id") + .from( + StripeIncreaseBalanceReceipt::Table, + StripeIncreaseBalanceReceipt::DepositToUserId, + ) + .to(User::Table, User::Id), + ) + .col( + ColumnDef::new(StripeIncreaseBalanceReceipt::Amount) + .decimal_len(20, 10) + .not_null(), + ) + .col( + ColumnDef::new(StripeIncreaseBalanceReceipt::Currency) + .string() + .not_null(), + ) + .col( + ColumnDef::new(StripeIncreaseBalanceReceipt::Status) + .string() + .not_null(), + ) + .col(ColumnDef::new(StripeIncreaseBalanceReceipt::Description).string()) + .col( + ColumnDef::new(StripeIncreaseBalanceReceipt::DateCreated) + .timestamp() + .not_null(), + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table( + Table::drop() + .table(StripeIncreaseBalanceReceipt::Table) + .to_owned(), + ) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum User { + Table, + Id, +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum StripeIncreaseBalanceReceipt { + Table, + Id, + StripePaymentIntendId, + Amount, + Currency, + Status, + DepositToUserId, + Description, + DateCreated, +} diff --git a/scripts/manual-tests/135-stripe-deposit.sh b/scripts/manual-tests/135-stripe-deposit.sh new file mode 100644 index 00000000..e69de29b diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 4730e14f..f18ad7b1 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -82,13 +82,15 @@ 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"] } +async-stripe = { version = "0.22.2", features = ["runtime-tokio-hyper-rustls"] } 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_json = { version = "1.0.99", default-features = false, features = ["raw_value"] } serde_prometheus = "0.2.3" strum = { version = "0.25.0", features = ["derive"] } -time = { version = "0.3.22" } +time_01 = { package = "time", version = "0.1" } +time_03 = { package = "time", version = "0.3" } tokio = { version = "1.29.0", features = ["full", "tracing"] } tokio-console = { version = "0.1.8", optional = true } tokio-stream = { version = "0.1.14", features = ["sync"] } diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index 16e42a80..15ce574c 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -166,6 +166,9 @@ pub struct AppConfig { /// Optionally send errors to pub sentry_url: Option, + /// Stripe api key from environment variable, + pub stripe_api_key: Option, + /// Track rate limits in a redis (or compatible backend) /// It is okay if this data is lost. pub volatile_redis_url: Option, diff --git a/web3_proxy/src/frontend/admin.rs b/web3_proxy/src/frontend/admin.rs index 43b4fe2b..9fddd4dc 100644 --- a/web3_proxy/src/frontend/admin.rs +++ b/web3_proxy/src/frontend/admin.rs @@ -34,7 +34,7 @@ use siwe::{Message, VerificationOpts}; use std::ops::Add; use std::str::FromStr; use std::sync::Arc; -use time::{Duration, OffsetDateTime}; +use time_03::{Duration, OffsetDateTime}; use tracing::{debug, info, warn}; use ulid::Ulid; diff --git a/web3_proxy/src/frontend/mod.rs b/web3_proxy/src/frontend/mod.rs index db0f18bc..252e347e 100644 --- a/web3_proxy/src/frontend/mod.rs +++ b/web3_proxy/src/frontend/mod.rs @@ -168,6 +168,11 @@ pub async fn serve( .route("/user", post(users::user_post)) .route("/user/balance", get(users::payment::user_balance_get)) .route("/user/deposits", get(users::payment::user_deposits_get)) + .route( + "/user/balance/stripe", + get(users::payment_stripe::user_stripe_deposits_get) + .post(users::payment_stripe::user_balance_stripe_post), + ) .route( "/user/balance/:tx_hash", post(users::payment::user_balance_post), diff --git a/web3_proxy/src/frontend/users/authentication.rs b/web3_proxy/src/frontend/users/authentication.rs index 149beea1..c05fd243 100644 --- a/web3_proxy/src/frontend/users/authentication.rs +++ b/web3_proxy/src/frontend/users/authentication.rs @@ -28,7 +28,7 @@ use siwe::{Message, VerificationOpts}; use std::ops::Add; use std::str::FromStr; use std::sync::Arc; -use time::{Duration, OffsetDateTime}; +use time_03::{Duration, OffsetDateTime}; use tracing::{error, trace, warn}; use ulid::Ulid; diff --git a/web3_proxy/src/frontend/users/mod.rs b/web3_proxy/src/frontend/users/mod.rs index ddc337fa..2cd61457 100644 --- a/web3_proxy/src/frontend/users/mod.rs +++ b/web3_proxy/src/frontend/users/mod.rs @@ -1,6 +1,7 @@ //! Handle registration, logins, and managing account data. pub mod authentication; pub mod payment; +pub mod payment_stripe; pub mod referral; pub mod rpc_keys; pub mod stats; diff --git a/web3_proxy/src/frontend/users/payment_stripe.rs b/web3_proxy/src/frontend/users/payment_stripe.rs new file mode 100644 index 00000000..f442df63 --- /dev/null +++ b/web3_proxy/src/frontend/users/payment_stripe.rs @@ -0,0 +1,250 @@ +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, +}; +use ethers::types::Address; +use http::HeaderMap; +use migration::sea_orm::prelude::Decimal; +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}; + +/// `GET /user/balance/stripe` -- Use a bearer token to get the user's balance and spend. +/// +/// - shows a list of all stripe deposits, all fields from entity +#[debug_handler] +pub async fn user_stripe_deposits_get( + Extension(app): Extension>, + TypedHeader(Authorization(bearer)): TypedHeader>, +) -> Web3ProxyResponse { + let (user, _semaphore) = app.bearer_is_authorized(bearer).await?; + + let db_replica = app.db_replica().context("Getting database connection")?; + + // Filter by user ... + let receipts = stripe_increase_balance_receipt::Entity::find() + .filter(increase_on_chain_balance_receipt::Column::DepositToUserId.eq(user.id)) + .all(db_replica.as_ref()) + .await?; + + // Return the response, all except the user ... + let response = json!({ + "user": Address::from_slice(&user.address), + "deposits": receipts, + }); + + 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, + // referral_code: Option, + 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] +pub async fn user_balance_stripe_post( + Extension(app): Extension>, + 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: is handling this as internal fine? + let authorization = Web3ProxyAuthorization::internal(app.db_conn().ok().cloned())?; + + (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 + let signature = headers + .get("STRIPE_SIGNATURE") + .ok_or(Web3ProxyError::BadRequest( + "You have not provided a 'STRIPE_SIGNATURE' for the Stripe payload".into(), + ))? + .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 intent = match event.data.object { + stripe::EventObject::PaymentIntent(intent) => intent, + _ => return Ok("Received irrelevant webhook".into_response()), + }; + debug!("Found PaymentIntent Event: {:?}", intent); + + if intent.status.as_str() != "succeeded" { + return Ok("Received Webhook".into_response()); + } + + let db_conn = app.db_conn().context("query_user_stats needs a db")?; + + if stripe_increase_balance_receipt::Entity::find() + .filter( + stripe_increase_balance_receipt::Column::StripePaymentIntendId.eq(intent.id.as_str()), + ) + .one(db_conn) + .await? + .is_some() + { + return Ok("Payment was already recorded".into_response()); + }; + + // Try to get the recipient_user_id from the data metadata + let recipient_user_id = match intent.metadata.get("user_id") { + Some(x) => Ok(x.parse::()), + None => Err(Web3ProxyError::BadRequest( + "Could not find user_id in the stripe webhook request!".into(), + )), + }? + .context(Web3ProxyError::BadRequest( + "Could not parse the stripe webhook request user_id!".into(), + ))?; + + let recipient: Option = user::Entity::find_by_id(recipient_user_id) + .one(db_conn) + .await?; + + // we do a fixed 2 decimal points because we only accept USD for now + let amount = Decimal::new(intent.amount, 2); + let recipient_id: Option = recipient.as_ref().map(|x| x.id); + let insert_receipt_model = stripe_increase_balance_receipt::ActiveModel { + id: Default::default(), + deposit_to_user_id: sea_orm::Set(recipient_id), + amount: sea_orm::Set(amount), + stripe_payment_intend_id: sea_orm::Set(intent.id.as_str().to_string()), + currency: sea_orm::Set(intent.currency.to_string()), + status: sea_orm::Set(intent.status.to_string()), + description: sea_orm::Set(intent.description), + date_created: Default::default(), + }; + + // In all these cases, we should record the transaction, but not increase the balance + let txn = db_conn.begin().await?; + + // Assert that it's usd + 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 + error!( + currency=%intent.currency, %recipient_user_id, %intent.id, + "Please refund this transaction!", + ); + let _ = insert_receipt_model.save(&txn).await; + txn.commit().await?; + return Ok("Received Webhook".into_response()); + } + // Otherwise, also increase the balance ... + match recipient { + Some(recipient) => { + // Create a balance update as well + let balance_entry = balance::ActiveModel { + id: sea_orm::NotSet, + total_deposits: sea_orm::Set(amount), + user_id: sea_orm::Set(recipient.id), + ..Default::default() + }; + trace!(?balance_entry, "Trying to insert into balance entry"); + balance::Entity::insert(balance_entry) + .on_conflict( + OnConflict::new() + .values([( + balance::Column::TotalDeposits, + Expr::col(balance::Column::TotalDeposits).add(amount), + )]) + .to_owned(), + ) + .exec(&txn) + .await + .web3_context("increasing balance")?; + + let _ = insert_receipt_model.save(&txn).await; + + let recipient_rpc_keys = rpc_key::Entity::find() + .filter(rpc_key::Column::UserId.eq(recipient.id)) + .all(&txn) + .await?; + + txn.commit().await?; + + // Finally invalidate the cache as well + match NonZeroU64::try_from(recipient.id) { + Err(_) => {} + Ok(x) => { + app.user_balance_cache.invalidate(&x).await; + } + }; + for rpc_key_entity in recipient_rpc_keys { + app.rpc_secret_key_cache + .invalidate(&rpc_key_entity.secret_key.into()) + .await; + } + } + None => { + return Err(Web3ProxyError::BadResponse( + "We just checked if the recipient is not none, it should've branched before!" + .into(), + )) + } + }; + + Ok("Received webhook".into_response()) +} diff --git a/web3_proxy/src/pagerduty.rs b/web3_proxy/src/pagerduty.rs index 90cc4d1e..32a663d3 100644 --- a/web3_proxy/src/pagerduty.rs +++ b/web3_proxy/src/pagerduty.rs @@ -8,7 +8,7 @@ use std::{ hash::{Hash, Hasher}, panic::PanicInfo, }; -use time::OffsetDateTime; +use time_03::OffsetDateTime; use tracing::{debug, error, warn}; /* diff --git a/web3_proxy/tests/common/app.rs b/web3_proxy/tests/common/app.rs index 1c9bf57f..b1dde01c 100644 --- a/web3_proxy/tests/common/app.rs +++ b/web3_proxy/tests/common/app.rs @@ -25,19 +25,19 @@ use web3_proxy::{ pub struct TestApp { /// anvil shuts down when this guard is dropped. - anvil: AnvilInstance, - - /// spawn handle for the proxy. - handle: Mutex>>>, - - /// tell the app to shut down (use `self.stop()`). - shutdown_sender: broadcast::Sender<()>, + pub anvil: AnvilInstance, /// connection to anvil. pub anvil_provider: Provider, + /// spawn handle for the proxy. + pub handle: Mutex>>>, + /// connection to the proxy that is connected to anil. pub proxy_provider: Provider, + + /// tell the app to shut down (use `self.stop()`). + shutdown_sender: broadcast::Sender<()>, } impl TestApp {