diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..c810fde --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,18 @@ +name: Coverage +on: [pull_request, push] +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + run: rustup toolchain install nightly --component llvm-tools-preview + - name: Install cargo-llvm-cov + run: curl -LsSf https://github.com/taiki-e/cargo-llvm-cov/releases/latest/download/cargo-llvm-cov-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin + - name: Generate code coverage + run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + files: lcov.info + fail_ci_if_error: true diff --git a/Cargo.lock b/Cargo.lock index 5febd06..19bbccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,81 +26,12 @@ dependencies = [ "memchr", ] -[[package]] -name = "anstream" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" - -[[package]] -name = "anstyle-parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" -dependencies = [ - "anstyle", - "windows-sys", -] - [[package]] name = "anyhow" version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "async-stream" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22068c0c19514942eefcfd4daf8976ef1aad84e61539f95cd200c35202f80af5" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "async-trait" version = "0.1.74" @@ -118,51 +49,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "axum" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" -dependencies = [ - "async-trait", - "axum-core", - "bitflags 1.3.2", - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - [[package]] name = "backtrace" version = "0.3.69" @@ -180,9 +66,18 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +dependencies = [ + "serde", +] [[package]] name = "bitflags" @@ -191,10 +86,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "bitflags" -version = "2.4.1" +name = "block-buffer" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] [[package]] name = "bytes" @@ -218,56 +116,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "clap" -version = "4.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.4.7" +name = "cpufeatures" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", + "libc", ] [[package]] -name = "clap_derive" -version = "4.4.7" +name = "ctor" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "30d2b3721e861707777e3195b0158f950ae6dc4a27e4d02ff9f67e3eb3de199e" dependencies = [ - "heck", - "proc-macro2", "quote", "syn 2.0.39", ] [[package]] -name = "clap_lex" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" - -[[package]] -name = "colorchoice" -version = "1.0.0" +name = "digest" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] [[package]] name = "equivalent" @@ -275,34 +149,26 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "futures" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.29" @@ -310,6 +176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -318,6 +185,23 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +[[package]] +name = "futures-io" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" + +[[package]] +name = "futures-macro" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "futures-sink" version = "0.3.29" @@ -336,26 +220,43 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] name = "gateway" version = "0.1.0" dependencies = [ - "async-stream", - "clap", - "http", - "prost", + "anyhow", + "async-trait", + "ctor", + "jsonrpsee", + "log", + "serde", + "thiserror", "tokio", "tokio-stream", - "tonic", - "tonic-build", - "tonic-web", - "tower-http", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", ] [[package]] @@ -418,15 +319,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" -[[package]] -name = "home" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" -dependencies = [ - "windows-sys", -] - [[package]] name = "http" version = "0.2.9" @@ -449,12 +341,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "http-range-header" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" - [[package]] name = "httparse" version = "1.8.0" @@ -484,25 +370,12 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", "tokio", "tower-service", "tracing", "want", ] -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "inbox" version = "0.1.0" @@ -528,19 +401,96 @@ dependencies = [ ] [[package]] -name = "itertools" -version = "0.10.5" +name = "itoa" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "jsonrpsee" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9579d0ca9fb30da026bac2f0f7d9576ec93489aeb7cd4971dd5b4617d82c79b2" dependencies = [ - "either", + "jsonrpsee-core", + "jsonrpsee-proc-macros", + "jsonrpsee-server", + "jsonrpsee-types", + "tokio", + "tracing", ] [[package]] -name = "itoa" -version = "1.0.9" +name = "jsonrpsee-core" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "776d009e2f591b78c038e0d053a796f94575d66ca4e77dd84bfc5e81419e436c" +dependencies = [ + "anyhow", + "async-trait", + "beef", + "futures-util", + "hyper", + "jsonrpsee-types", + "parking_lot", + "rand", + "rustc-hash", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "jsonrpsee-proc-macros" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d94b7505034e2737e688e1153bf81e6f93ad296695c43958d6da2e4321f0a990" +dependencies = [ + "heck", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "jsonrpsee-server" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc7c6d1a2c58f6135810284a390d9f823d0f508db74cd914d8237802de80f98" +dependencies = [ + "futures-util", + "http", + "hyper", + "jsonrpsee-core", + "jsonrpsee-types", + "pin-project", + "route-recognizer", + "serde", + "serde_json", + "soketto", + "thiserror", + "tokio", + "tokio-stream", + "tokio-util", + "tower", + "tracing", +] + +[[package]] +name = "jsonrpsee-types" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3266dfb045c9174b24c77c2dfe0084914bb23a6b2597d70c9dc6018392e1cd1b" +dependencies = [ + "anyhow", + "beef", + "serde", + "serde_json", + "thiserror", +] [[package]] name = "lazy_static" @@ -555,10 +505,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] -name = "linux-raw-sys" +name = "lock_api" version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] [[package]] name = "log" @@ -567,10 +521,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] -name = "matchit" -version = "0.7.3" +name = "matchers" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] [[package]] name = "memchr" @@ -582,12 +539,6 @@ checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" name = "messaging" version = "0.1.0" -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -609,10 +560,14 @@ dependencies = [ ] [[package]] -name = "multimap" -version = "0.8.3" +name = "nu-ansi-term" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] [[package]] name = "num_cpus" @@ -640,19 +595,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] -name = "percent-encoding" -version = "2.3.0" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "petgraph" -version = "0.6.4" +name = "overload" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "fixedbitset", - "indexmap 2.1.0", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", ] [[package]] @@ -694,13 +668,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] -name = "prettyplease" -version = "0.1.25" +name = "proc-macro-crate" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" dependencies = [ - "proc-macro2", - "syn 1.0.109", + "toml_datetime", + "toml_edit", ] [[package]] @@ -712,60 +686,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-build" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" -dependencies = [ - "bytes", - "heck", - "itertools", - "lazy_static", - "log", - "multimap", - "petgraph", - "prettyplease", - "prost", - "prost-types", - "regex", - "syn 1.0.109", - "tempfile", - "which", -] - -[[package]] -name = "prost-derive" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "prost-types" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" -dependencies = [ - "prost", -] - [[package]] name = "quote" version = "1.0.33" @@ -811,7 +731,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -822,8 +742,17 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -834,9 +763,15 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.2" @@ -847,6 +782,12 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" name = "registry" version = "0.1.0" +[[package]] +name = "route-recognizer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -854,23 +795,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] -name = "rustix" -version = "0.38.21" +name = "rustc-hash" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" -dependencies = [ - "bitflags 2.4.1", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] -name = "rustversion" -version = "1.0.14" +name = "scopeguard" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" @@ -892,6 +832,39 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "serde_json" +version = "1.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "slab" version = "0.4.9" @@ -902,14 +875,10 @@ dependencies = [ ] [[package]] -name = "socket2" -version = "0.4.10" +name = "smallvec" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "socket2" @@ -922,10 +891,20 @@ dependencies = [ ] [[package]] -name = "strsim" -version = "0.10.0" +name = "soketto" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" +dependencies = [ + "base64", + "bytes", + "futures", + "http", + "httparse", + "log", + "rand", + "sha-1", +] [[package]] name = "syn" @@ -950,22 +929,33 @@ dependencies = [ ] [[package]] -name = "sync_wrapper" -version = "0.1.2" +name = "thiserror" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +dependencies = [ + "thiserror-impl", +] [[package]] -name = "tempfile" -version = "3.8.1" +name = "thiserror-impl" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ "cfg-if", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys", + "once_cell", ] [[package]] @@ -980,21 +970,11 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys", ] -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-macros" version = "2.1.0" @@ -1025,6 +1005,7 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -1032,64 +1013,20 @@ dependencies = [ ] [[package]] -name = "tonic" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" -dependencies = [ - "async-trait", - "axum", - "base64", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "tokio", - "tokio-stream", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tonic-build" -version = "0.9.2" +name = "toml_datetime" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6fdaae4c2c638bb70fe42803a26fbd6fc6ac8c72f5c59f67ecc2a2dcabf4b07" -dependencies = [ - "prettyplease", - "proc-macro2", - "prost-build", - "quote", - "syn 1.0.109", -] +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] -name = "tonic-web" -version = "0.9.2" +name = "toml_edit" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b00ec4842256d1fe0a46176e2ef5bc357664c66e7d91aff5a7d43d83a65f47" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ - "base64", - "bytes", - "futures-core", - "http", - "http-body", - "hyper", - "pin-project", - "tonic", - "tower-http", - "tower-layer", - "tower-service", - "tracing", + "indexmap 2.1.0", + "toml_datetime", + "winnow", ] [[package]] @@ -1098,38 +1035,11 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ - "futures-core", - "futures-util", - "indexmap 1.9.3", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util", "tower-layer", "tower-service", "tracing", ] -[[package]] -name = "tower-http" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" -dependencies = [ - "bitflags 2.4.1", - "bytes", - "futures-core", - "futures-util", - "http", - "http-body", - "http-range-header", - "pin-project-lite", - "tower-layer", - "tower-service", -] - [[package]] name = "tower-layer" version = "0.3.2" @@ -1148,6 +1058,7 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -1171,6 +1082,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -1179,6 +1120,12 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" @@ -1186,10 +1133,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "utf8parse" -version = "0.2.1" +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "want" @@ -1206,18 +1159,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - [[package]] name = "winapi" version = "0.3.9" @@ -1305,3 +1246,12 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +dependencies = [ + "memchr", +] diff --git a/Dockerfile b/Dockerfile index 58423b1..c8b28a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM ghcr.io/xmtp/rust:latest USER xmtp +RUN sudo apt update && sudo apt install -y pkg-config openssl libssl-dev + ARG PROJECT=xps-gateway WORKDIR /workspaces/${PROJECT} COPY --chown=xmtp:xmtp . . diff --git a/xps-gateway/Cargo.toml b/xps-gateway/Cargo.toml index 42e94b2..4a4b801 100644 --- a/xps-gateway/Cargo.toml +++ b/xps-gateway/Cargo.toml @@ -2,21 +2,19 @@ name = "gateway" version = "0.1.0" edition = "2021" +resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tonic = "0.9" -prost = "0.11" -http = "0.2.9" +log = "0.4" +tracing = "0.1" +tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] } +serde = "1" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } tokio-stream = { version = "0.1", features = ["net"] } -async-stream = "0.2" -clap = { version = "4.3.21", features = ["derive"] } -tonic-web = "0.9.2" -tower-http = { version = "0.4.0", default-features = false, features = [ - "cors", -] } - -[build-dependencies] -tonic-build = "0.9" +async-trait = "0.1" +jsonrpsee = { version = "0.21", features = ["macros", "server", "client-core"] } +anyhow = "1" +thiserror = "1" +ctor = "0.2" diff --git a/xps-gateway/build.rs b/xps-gateway/build.rs deleted file mode 100644 index 6b23d5f..0000000 --- a/xps-gateway/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() -> Result<(), Box> { - tonic_build::compile_protos("proto/inbox_v1.proto")?; - - Ok(()) -} diff --git a/xps-gateway/proto/inbox_v1.proto b/xps-gateway/proto/inbox_v1.proto deleted file mode 100644 index 67d3bde..0000000 --- a/xps-gateway/proto/inbox_v1.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; -package xmtp.gateway.inbox.v1; - -service Inbox { - rpc SendMessage(SendMessageRequest) returns (SendMessageResponse); - rpc GetMessages(GetMessagesRequest) returns (stream Envelope); -} - -message Envelope { - string inbox = 1; - bytes message = 2; -} - -message SendMessageRequest { repeated Envelope envelopes = 1; } - -message SendMessageResponse { string transaction_id = 1; } - -message GetMessagesRequest { - string inbox = 1; - bool follow = 2; - uint64 start_at = 3; - uint64 end_at = 4; -} diff --git a/xps-gateway/src/inbox/mod.rs b/xps-gateway/src/inbox/mod.rs deleted file mode 100644 index a3a6d96..0000000 --- a/xps-gateway/src/inbox/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod v1; diff --git a/xps-gateway/src/inbox/v1.rs b/xps-gateway/src/inbox/v1.rs deleted file mode 100644 index 7d5b869..0000000 --- a/xps-gateway/src/inbox/v1.rs +++ /dev/null @@ -1,130 +0,0 @@ -use std::{pin::Pin, time::Duration}; -use tokio::sync::mpsc; -use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt}; -use tonic::{Request, Response, Status}; - -use proto::inbox_server::Inbox; -use proto::{Envelope, GetMessagesRequest, SendMessageRequest, SendMessageResponse}; - -pub mod proto { - tonic::include_proto!("xmtp.gateway.inbox.v1"); -} - -#[derive(Debug, Default)] -pub struct InboxService {} - -#[tonic::async_trait] -impl Inbox for InboxService { - type GetMessagesStream = Pin> + Send>>; - - async fn send_message( - &self, - _request: Request, - ) -> Result, Status> { - // TODO: Push message contents to IPFS and get CID - // TODO: Build and submit blockchain smart contract transaction. - let resp = SendMessageResponse { - transaction_id: "TODO".to_string(), - }; - Ok(Response::new(resp)) - } - - async fn get_messages( - &self, - _request: Request, - ) -> Result, Status> { - let repeat = std::iter::repeat(Envelope { - inbox: "inbox".to_string(), - message: Vec::new(), - }); - let mut stream = Box::pin(tokio_stream::iter(repeat).throttle(Duration::from_millis(200))); - - // TODO: stream events from smart contract based on recipient - - // spawn and channel are required if you want handle "disconnect" functionality - // the `out_stream` will not be polled after client disconnect - let (tx, rx) = mpsc::channel(128); - tokio::spawn(async move { - while let Some(item) = stream.next().await { - match tx.send(Result::<_, Status>::Ok(item)).await { - Ok(_) => { - // item (server response) was queued to be sent to client - } - Err(_item) => { - // output_stream was build from rx and both are dropped - break; - } - } - } - println!("\tclient disconnected"); - }); - - let output_stream = ReceiverStream::new(rx); - Ok(Response::new( - Box::pin(output_stream) as Self::GetMessagesStream - )) - } -} - -#[cfg(test)] -mod tests { - use crate::inbox::v1::proto::inbox_server::Inbox; - use crate::inbox::v1::proto::{Envelope, GetMessagesRequest, SendMessageRequest}; - use crate::inbox::v1::InboxService; - use tokio_stream::StreamExt; - use tonic::Request; - - fn build_service() -> InboxService { - InboxService {} - } - - #[tokio::test] - async fn test_send_message() { - let service = build_service(); - let resp = service - .send_message(Request::new(SendMessageRequest { - envelopes: Vec::new(), - })) - .await; - assert!(resp.is_ok()); - } - - #[tokio::test] - async fn test_get_messages() { - let service = build_service(); - let resp = service - .get_messages(Request::new(GetMessagesRequest { - inbox: "inbox".to_string(), - follow: true, - start_at: 0, - end_at: 0, - })) - .await; - assert!(resp.is_ok()); - let mut resp = resp.unwrap().into_inner(); - let envelope1 = resp - .next() - .await - .expect("streamed response is Some") - .expect("response is ok"); - assert_eq!( - envelope1, - Envelope { - inbox: "inbox".to_string(), - message: Vec::new(), - } - ); - let envelope2 = resp - .next() - .await - .expect("streamed response is Some") - .expect("response is ok"); - assert_eq!( - envelope2, - Envelope { - inbox: "inbox".to_string(), - message: Vec::new(), - } - ); - } -} diff --git a/xps-gateway/src/lib.rs b/xps-gateway/src/lib.rs new file mode 100644 index 0000000..2e430c4 --- /dev/null +++ b/xps-gateway/src/lib.rs @@ -0,0 +1,22 @@ +mod rpc; +mod types; +mod util; + +use anyhow::Result; +use jsonrpsee::server::Server; + +pub use crate::rpc::{XpsMethods, XpsServer}; + +/// Entrypoint for the xps Gateway +pub async fn run() -> Result<()> { + crate::util::init_logging(); + + // a port of 0 allows the OS to choose an open port + let server = Server::builder().build("127.0.0.1:0").await?; + let addr = server.local_addr()?; + let handle = server.start(rpc::XpsMethods.into_rpc()); + + log::info!("Server Started at {addr}"); + handle.stopped().await; + Ok(()) +} diff --git a/xps-gateway/src/main.rs b/xps-gateway/src/main.rs index d57bee3..77fc062 100644 --- a/xps-gateway/src/main.rs +++ b/xps-gateway/src/main.rs @@ -1,68 +1,8 @@ -use std::net::SocketAddr; -use std::time::Duration; - -use http::header::HeaderName; -use tonic::transport::Server; -use tonic_web::GrpcWebLayer; -use tower_http::cors::{AllowOrigin, CorsLayer}; - -mod inbox; - -use inbox::v1::proto::inbox_server::InboxServer; - -use clap::Parser; - -/// XMTP RPC node -#[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] -struct Args { - /// Port to listen on for public gRPC - #[arg(short, long, default_value_t = 50051)] - port: u16, -} - -const DEFAULT_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60); -const DEFAULT_EXPOSED_HEADERS: [&str; 3] = - ["grpc-status", "grpc-message", "grpc-status-details-bin"]; -const DEFAULT_ALLOW_HEADERS: [&str; 4] = - ["x-grpc-web", "content-type", "x-user-agent", "grpc-timeout"]; +use anyhow::Result; +use gateway::run; #[tokio::main] -async fn main() -> Result<(), Box> { - let args = Args::parse(); - - let inbox_v1 = inbox::v1::InboxService::default(); - - let addr: SocketAddr = format!("[::1]:{}", args.port).parse()?; - let server = Server::builder() - .accept_http1(true) - .layer( - CorsLayer::new() - .allow_origin(AllowOrigin::mirror_request()) - .allow_credentials(true) - .max_age(DEFAULT_MAX_AGE) - .expose_headers( - DEFAULT_EXPOSED_HEADERS - .iter() - .cloned() - .map(HeaderName::from_static) - .collect::>(), - ) - .allow_headers( - DEFAULT_ALLOW_HEADERS - .iter() - .cloned() - .map(HeaderName::from_static) - .collect::>(), - ), - ) - .layer(GrpcWebLayer::new()) - .add_service(InboxServer::new(inbox_v1)); - - let listener = tokio::net::TcpListener::bind(addr).await?; - println!("Listening on {}", listener.local_addr().unwrap()); - let stream = tokio_stream::wrappers::TcpListenerStream::new(listener); - server.serve_with_incoming(stream).await?; - +async fn main() -> Result<()> { + crate::run().await?; Ok(()) } diff --git a/xps-gateway/src/rpc.rs b/xps-gateway/src/rpc.rs new file mode 100644 index 0000000..8640e53 --- /dev/null +++ b/xps-gateway/src/rpc.rs @@ -0,0 +1,6 @@ +//! RPC Interface and Implementations for XPS +mod api; +mod methods; + +pub use api::*; +pub use methods::*; diff --git a/xps-gateway/src/rpc/api.rs b/xps-gateway/src/rpc/api.rs new file mode 100644 index 0000000..c1ec944 --- /dev/null +++ b/xps-gateway/src/rpc/api.rs @@ -0,0 +1,13 @@ +//! Trait Interface Definitions for XPS JSON-RPC + +use jsonrpsee::{proc_macros::rpc, types::ErrorObjectOwned}; + +use crate::types::Message; + +/// XPS JSON-RPC Interface Methods +#[rpc(server, client, namespace = "xps")] +pub trait Xps { + // Placeholder for send_message, see [the discussion](https://github.com/xmtp/xps-gateway/discussions/11) + #[method(name = "sendMessage")] + async fn send_message(&self, _message: Message) -> Result<(), ErrorObjectOwned>; +} diff --git a/xps-gateway/src/rpc/methods.rs b/xps-gateway/src/rpc/methods.rs new file mode 100644 index 0000000..6dc1556 --- /dev/null +++ b/xps-gateway/src/rpc/methods.rs @@ -0,0 +1,20 @@ +//! Interface Implementations for XPS JSON-RPC + +use super::api::*; + +use async_trait::async_trait; +use jsonrpsee::types::ErrorObjectOwned; + +use crate::types::Message; + +/// Gateway Methods for XPS +pub struct XpsMethods; + +#[async_trait] +impl XpsServer for XpsMethods { + async fn send_message(&self, _message: Message) -> Result<(), ErrorObjectOwned> { + //TODO: Stub for sendMessage, ref: [discussion](https://github.com/xmtp/xps-gateway/discussions/11) + log::debug!("xps_sendMessage called"); + todo!(); + } +} diff --git a/xps-gateway/src/types.rs b/xps-gateway/src/types.rs new file mode 100644 index 0000000..c734427 --- /dev/null +++ b/xps-gateway/src/types.rs @@ -0,0 +1,17 @@ +use serde::{Deserialize, Serialize}; + +/// A message sent to a conversation +#[derive(Serialize, Deserialize)] +pub struct Message { + // Unique identifier for a conversation + #[serde(rename = "groupId")] + group_id: Vec, + /// message content in bytes + payload: Vec, + /// Signature of V + v: Vec, + /// Signature of R + r: Vec, + /// Signature of S + s: Vec, +} diff --git a/xps-gateway/src/util.rs b/xps-gateway/src/util.rs new file mode 100644 index 0000000..f1b0d3c --- /dev/null +++ b/xps-gateway/src/util.rs @@ -0,0 +1,28 @@ +//! Internal Utility functions for use in crate + +#[cfg(test)] +use std::sync::Once; +use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry}; + +#[cfg(test)] +static INIT: Once = Once::new(); + +pub(crate) fn init_logging() { + let fmt = fmt::layer().compact(); + Registry::default().with(env()).with(fmt).init() +} + +#[cfg(test)] +#[ctor::ctor] +fn __init_test_logging() { + INIT.call_once(|| { + let fmt = fmt::layer().compact(); + Registry::default().with(env()).with(fmt).init() + }) +} + +/// Try to get the logging environment from the `RUST_LOG` environment variable. +/// If it is not set, use the default of `info`. +fn env() -> EnvFilter { + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")) +} diff --git a/xps-gateway/tests/integration_test.rs b/xps-gateway/tests/integration_test.rs new file mode 100644 index 0000000..1bf4e99 --- /dev/null +++ b/xps-gateway/tests/integration_test.rs @@ -0,0 +1,4 @@ +#[test] +fn test_it_works() { + assert_eq!(2 + 2, 4); +}