From 3dc3b40438e2c1938154318463b3d3a70412dc26 Mon Sep 17 00:00:00 2001 From: vegetabledogdog Date: Mon, 1 Jul 2024 23:02:20 +0800 Subject: [PATCH 1/4] [deps] update rpc deps --- Cargo.lock | 574 +++++++++++++----- Cargo.toml | 15 +- crates/rooch-faucet/Cargo.toml | 1 + crates/rooch-faucet/src/web.rs | 2 +- crates/rooch-rpc-client/src/client_config.rs | 5 - crates/rooch-rpc-client/src/lib.rs | 10 +- crates/rooch-rpc-client/src/wallet_context.rs | 2 +- crates/rooch-rpc-server/Cargo.toml | 4 +- crates/rooch-rpc-server/src/lib.rs | 20 +- .../rooch-rpc-server/src/server/btc_server.rs | 26 +- .../src/server/rooch_server.rs | 180 ++++-- crates/rooch-rpc-server/src/service/mod.rs | 1 - .../src/service/rpc_logger.rs | 80 --- crates/rooch/src/commands/env/commands/add.rs | 2 +- .../src/natives/ord/inscription.rs | 2 +- 15 files changed, 588 insertions(+), 336 deletions(-) delete mode 100644 crates/rooch-rpc-server/src/service/rpc_logger.rs diff --git a/Cargo.lock b/Cargo.lock index 5d276d6d36..a32465668c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -684,7 +684,7 @@ dependencies = [ "async-ws", "futures", "futures-rustls", - "gloo-net", + "gloo-net 0.2.6", "http 1.1.0", "js-sys", "lazy_static 1.5.0", @@ -805,12 +805,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", - "base64 0.21.7", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", - "headers", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", @@ -825,10 +823,44 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", + "sync_wrapper 0.1.2", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core 0.4.3", + "base64 0.21.7", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde 1.0.203", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", "sha1", - "sync_wrapper", + "sync_wrapper 1.0.1", "tokio", - "tokio-tungstenite 0.20.1", + "tokio-tungstenite 0.21.0", "tower", "tower-layer", "tower-service", @@ -851,6 +883,26 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", +] + [[package]] name = "axum-server" version = "0.5.1" @@ -871,6 +923,29 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum-server" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad46c3ec4e12f4a4b6835e173ba21c25e484c9d02b49770bf006ce5367c036" +dependencies = [ + "arc-swap", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-util", + "pin-project-lite", + "rustls 0.21.12", + "rustls-pemfile 2.1.2", + "tokio", + "tokio-rustls 0.24.1", + "tower", + "tower-service", +] + [[package]] name = "backon" version = "0.4.4" @@ -1134,7 +1209,7 @@ name = "bitcoin-move" version = "0.5.7" dependencies = [ "anyhow", - "axum", + "axum 0.7.5", "bcs", "better_any", "bitcoin 0.31.2", @@ -1754,6 +1829,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cexpr" version = "0.6.0" @@ -4523,11 +4604,26 @@ name = "gloo-net" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10" +dependencies = [ + "gloo-utils 0.1.7", + "js-sys", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "gloo-net" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43aaa242d1239a8822c15c645f02166398da4f8b5c4bae795c1f5b44e9eee173" dependencies = [ "futures-channel", "futures-core", "futures-sink", - "gloo-utils", + "gloo-utils 0.2.0", + "http 0.2.12", "js-sys", "pin-project", "serde 1.0.203", @@ -4555,6 +4651,17 @@ name = "gloo-utils" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e" +dependencies = [ + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-utils" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa" dependencies = [ "js-sys", "serde 1.0.203", @@ -4686,30 +4793,6 @@ dependencies = [ "num-traits 0.2.19", ] -[[package]] -name = "headers" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" -dependencies = [ - "base64 0.21.7", - "bytes", - "headers-core", - "http 0.2.12", - "httpdate", - "mime", - "sha1", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http 0.2.12", -] - [[package]] name = "heck" version = "0.3.3" @@ -4871,6 +4954,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" +[[package]] +name = "http-range-header" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a397c49fec283e3d6211adbe480be95aae5f304cfb923e9970e08956d5168a" + [[package]] name = "httparse" version = "1.8.0" @@ -4935,6 +5024,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.0", "httparse", + "httpdate", "itoa", "pin-project-lite", "smallvec 1.13.2", @@ -4953,10 +5043,9 @@ dependencies = [ "hyper 0.14.28", "log", "rustls 0.21.12", - "rustls-native-certs", + "rustls-native-certs 0.6.3", "tokio", "tokio-rustls 0.24.1", - "webpki-roots 0.25.4", ] [[package]] @@ -4976,6 +5065,24 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.3.1", + "hyper-util", + "log", + "rustls 0.23.10", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", +] + [[package]] name = "hyper-timeout" version = "0.4.1" @@ -5378,6 +5485,26 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jni" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + [[package]] name = "jobserver" version = "0.1.31" @@ -5432,23 +5559,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "jsonrpsee" -version = "0.16.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "367a292944c07385839818bb71c8d76611138e2dedb0677d035b8da21d29c78b" -dependencies = [ - "jsonrpsee-client-transport 0.16.3", - "jsonrpsee-core 0.16.3", - "jsonrpsee-http-client 0.16.3", - "jsonrpsee-proc-macros 0.16.3", - "jsonrpsee-server", - "jsonrpsee-types 0.16.3", - "jsonrpsee-wasm-client", - "jsonrpsee-ws-client 0.16.3", - "tracing", -] - [[package]] name = "jsonrpsee" version = "0.20.3" @@ -5463,46 +5573,64 @@ dependencies = [ "tracing", ] +[[package]] +name = "jsonrpsee" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b089779ad7f80768693755a031cc14a7766aba707cbe886674e3f79e9b7e47" +dependencies = [ + "jsonrpsee-client-transport 0.23.2", + "jsonrpsee-core 0.23.2", + "jsonrpsee-http-client 0.23.2", + "jsonrpsee-proc-macros 0.23.2", + "jsonrpsee-server", + "jsonrpsee-types 0.23.2", + "jsonrpsee-wasm-client", + "jsonrpsee-ws-client 0.23.2", + "tokio", + "tracing", +] + [[package]] name = "jsonrpsee-client-transport" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8b3815d9f5d5de348e5f162b316dc9cdf4548305ebb15b4eb9328e66cf27d7a" +checksum = "b5b005c793122d03217da09af68ba9383363caa950b90d3436106df8cabce935" dependencies = [ - "anyhow", - "futures-channel", - "futures-timer", "futures-util", - "gloo-net", "http 0.2.12", - "jsonrpsee-core 0.16.3", - "jsonrpsee-types 0.16.3", + "jsonrpsee-core 0.20.3", "pin-project", - "rustls-native-certs", - "soketto", + "rustls-native-certs 0.6.3", + "soketto 0.7.1", "thiserror", "tokio", "tokio-rustls 0.24.1", "tokio-util", "tracing", - "webpki-roots 0.25.4", + "url", ] [[package]] name = "jsonrpsee-client-transport" -version = "0.20.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b005c793122d03217da09af68ba9383363caa950b90d3436106df8cabce935" +checksum = "08163edd8bcc466c33d79e10f695cdc98c00d1e6ddfb95cec41b6b0279dd5432" dependencies = [ + "base64 0.22.1", + "futures-channel", "futures-util", - "http 0.2.12", - "jsonrpsee-core 0.20.3", + "gloo-net 0.5.0", + "http 1.1.0", + "jsonrpsee-core 0.23.2", "pin-project", - "rustls-native-certs", - "soketto", + "rustls 0.23.10", + "rustls-pki-types", + "rustls-platform-verifier", + "soketto 0.8.0", "thiserror", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls 0.26.0", "tokio-util", "tracing", "url", @@ -5510,85 +5638,91 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5dde66c53d6dcdc8caea1874a45632ec0fcf5b437789f1e45766a1512ce803" +checksum = "da2327ba8df2fdbd5e897e2b5ed25ce7f299d345b9736b6828814c3dbd1fd47b" dependencies = [ "anyhow", - "arrayvec 0.7.4", "async-lock", "async-trait", "beef", - "futures-channel", "futures-timer", "futures-util", - "globset", "hyper 0.14.28", - "jsonrpsee-types 0.16.3", - "parking_lot 0.12.3", - "rand 0.8.5", + "jsonrpsee-types 0.20.3", "rustc-hash", "serde 1.0.203", "serde_json", - "soketto", "thiserror", "tokio", "tracing", - "wasm-bindgen-futures", ] [[package]] name = "jsonrpsee-core" -version = "0.20.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2327ba8df2fdbd5e897e2b5ed25ce7f299d345b9736b6828814c3dbd1fd47b" +checksum = "79712302e737d23ca0daa178e752c9334846b08321d439fd89af9a384f8c830b" dependencies = [ "anyhow", - "async-lock", "async-trait", "beef", + "bytes", "futures-timer", "futures-util", - "hyper 0.14.28", - "jsonrpsee-types 0.20.3", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "jsonrpsee-types 0.23.2", + "parking_lot 0.12.3", + "pin-project", + "rand 0.8.5", "rustc-hash", "serde 1.0.203", "serde_json", "thiserror", "tokio", + "tokio-stream", "tracing", + "wasm-bindgen-futures", ] [[package]] name = "jsonrpsee-http-client" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e5f9fabdd5d79344728521bb65e3106b49ec405a78b66fbff073b72b389fa43" +checksum = "5f80c17f62c7653ce767e3d7288b793dfec920f97067ceb189ebdd3570f2bc20" dependencies = [ "async-trait", "hyper 0.14.28", "hyper-rustls 0.24.2", - "jsonrpsee-core 0.16.3", - "jsonrpsee-types 0.16.3", - "rustc-hash", + "jsonrpsee-core 0.20.3", + "jsonrpsee-types 0.20.3", "serde 1.0.203", "serde_json", "thiserror", "tokio", + "tower", "tracing", + "url", ] [[package]] name = "jsonrpsee-http-client" -version = "0.20.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f80c17f62c7653ce767e3d7288b793dfec920f97067ceb189ebdd3570f2bc20" +checksum = "2d90064e04fb9d7282b1c71044ea94d0bbc6eff5621c66f1a0bce9e9de7cf3ac" dependencies = [ "async-trait", - "hyper 0.14.28", - "hyper-rustls 0.24.2", - "jsonrpsee-core 0.20.3", - "jsonrpsee-types 0.20.3", + "base64 0.22.1", + "http-body 1.0.0", + "hyper 1.3.1", + "hyper-rustls 0.27.2", + "hyper-util", + "jsonrpsee-core 0.23.2", + "jsonrpsee-types 0.23.2", + "rustls 0.23.10", + "rustls-platform-verifier", "serde 1.0.203", "serde_json", "thiserror", @@ -5600,9 +5734,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44e8ab85614a08792b9bff6c8feee23be78c98d0182d4c622c05256ab553892a" +checksum = "29110019693a4fa2dbda04876499d098fa16d70eba06b1e6e2b3f1b251419515" dependencies = [ "heck 0.4.1", "proc-macro-crate 1.3.1", @@ -5613,32 +5747,38 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.20.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29110019693a4fa2dbda04876499d098fa16d70eba06b1e6e2b3f1b251419515" +checksum = "7895f186d5921065d96e16bd795e5ca89ac8356ec423fafc6e3d7cf8ec11aee4" dependencies = [ - "heck 0.4.1", - "proc-macro-crate 1.3.1", + "heck 0.5.0", + "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.36", - "syn 1.0.109", + "syn 2.0.65", ] [[package]] name = "jsonrpsee-server" -version = "0.16.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4d945a6008c9b03db3354fb3c83ee02d2faa9f2e755ec1dfb69c3551b8f4ba" +checksum = "654afab2e92e5d88ebd8a39d6074483f3f2bfdf91c5ac57fe285e7127cdd4f51" dependencies = [ - "futures-channel", + "anyhow", "futures-util", - "http 0.2.12", - "hyper 0.14.28", - "jsonrpsee-core 0.16.3", - "jsonrpsee-types 0.16.3", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-util", + "jsonrpsee-core 0.23.2", + "jsonrpsee-types 0.23.2", + "pin-project", + "route-recognizer", "serde 1.0.203", "serde_json", - "soketto", + "soketto 0.8.0", + "thiserror", "tokio", "tokio-stream", "tokio-util", @@ -5648,9 +5788,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245ba8e5aa633dd1c1e4fae72bce06e71f42d34c14a2767c6b4d173b57bee5e5" +checksum = "5be0be325642e850ed0bdff426674d2e66b2b7117c9be23a7caef68a2902b7d9" dependencies = [ "anyhow", "beef", @@ -5662,51 +5802,51 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.20.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be0be325642e850ed0bdff426674d2e66b2b7117c9be23a7caef68a2902b7d9" +checksum = "d9c465fbe385238e861fdc4d1c85e04ada6c1fd246161d26385c1b311724d2af" dependencies = [ - "anyhow", "beef", + "http 1.1.0", "serde 1.0.203", "serde_json", "thiserror", - "tracing", ] [[package]] name = "jsonrpsee-wasm-client" -version = "0.16.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e5df77c8f625d36e4cfb583c5a674eccebe32403fcfe42f7ceff7fac9324dd" +checksum = "4727ac037f834c6f04c0912cada7532dbddb54e92fbc64e33d6cb8c24af313c9" dependencies = [ - "jsonrpsee-client-transport 0.16.3", - "jsonrpsee-core 0.16.3", - "jsonrpsee-types 0.16.3", + "jsonrpsee-client-transport 0.23.2", + "jsonrpsee-core 0.23.2", + "jsonrpsee-types 0.23.2", ] [[package]] name = "jsonrpsee-ws-client" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1b3975ed5d73f456478681a417128597acd6a2487855fdb7b4a3d4d195bf5e" +checksum = "bca9cb3933ccae417eb6b08c3448eb1cb46e39834e5b503e395e5e5bd08546c0" dependencies = [ "http 0.2.12", - "jsonrpsee-client-transport 0.16.3", - "jsonrpsee-core 0.16.3", - "jsonrpsee-types 0.16.3", + "jsonrpsee-client-transport 0.20.3", + "jsonrpsee-core 0.20.3", + "jsonrpsee-types 0.20.3", + "url", ] [[package]] name = "jsonrpsee-ws-client" -version = "0.20.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca9cb3933ccae417eb6b08c3448eb1cb46e39834e5b503e395e5e5bd08546c0" +checksum = "1c28759775f5cb2f1ea9667672d3fe2b0e701d1f4b7b67954e60afe7fd058b5e" dependencies = [ - "http 0.2.12", - "jsonrpsee-client-transport 0.20.3", - "jsonrpsee-core 0.20.3", - "jsonrpsee-types 0.20.3", + "http 1.1.0", + "jsonrpsee-client-transport 0.23.2", + "jsonrpsee-core 0.23.2", + "jsonrpsee-types 0.23.2", "url", ] @@ -6135,7 +6275,7 @@ version = "0.5.7" dependencies = [ "anyhow", "futures", - "hyper 0.14.28", + "hyper 1.3.1", "log", "prometheus", "psutil", @@ -7734,8 +7874,8 @@ checksum = "b0a6938622f394e8d803e58b3a14e9dba0494e12a84acdb704ee9ecc333e6f3f" dependencies = [ "anyhow", "async-trait", - "axum", - "axum-server", + "axum 0.6.20", + "axum-server 0.5.1", "base64 0.22.1", "bech32 0.11.0", "bip39", @@ -7783,7 +7923,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-util", - "tower-http", + "tower-http 0.4.4", "urlencoding", ] @@ -9335,7 +9475,7 @@ dependencies = [ "serde 1.0.203", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 0.1.2", "system-configuration", "tokio", "tokio-native-tls", @@ -9386,7 +9526,7 @@ dependencies = [ "serde 1.0.203", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 0.1.2", "system-configuration", "tokio", "tokio-native-tls", @@ -9673,7 +9813,7 @@ dependencies = [ "fastcrypto", "futures", "hex", - "hyper 0.14.28", + "hyper 1.3.1", "lazy_static 1.5.0", "log", "move-binary-format", @@ -9722,7 +9862,7 @@ dependencies = [ "toml 0.8.14", "tonic", "tower", - "tower-http", + "tower-http 0.5.2", "tracing", "tracing-subscriber", ] @@ -9736,7 +9876,7 @@ dependencies = [ "coerce", "dirs", "dirs-next", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "moveos-config", "once_cell", "proptest", @@ -9813,7 +9953,7 @@ dependencies = [ "derive_builder 0.20.0", "futures", "itertools 0.13.0", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "log", "move-binary-format", "move-core-types", @@ -9847,7 +9987,8 @@ version = "0.5.7" dependencies = [ "anyhow", "async-trait", - "axum", + "axum 0.7.5", + "axum-server 0.6.0", "clap 4.5.8", "eyre", "futures", @@ -9869,7 +10010,7 @@ dependencies = [ "thiserror", "tokio", "tower", - "tower-http", + "tower-http 0.5.2", "tracing", "tracing-subscriber", ] @@ -10222,7 +10363,7 @@ dependencies = [ "coerce", "derive_builder 0.20.0", "futures", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "log", "move-core-types", "move-resource-viewer", @@ -10260,7 +10401,7 @@ dependencies = [ "coerce", "derive_builder 0.20.0", "futures", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "log", "move-core-types", "move-resource-viewer", @@ -10298,7 +10439,7 @@ dependencies = [ "fastcrypto", "futures", "hex", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "move-core-types", "move-resource-viewer", "moveos", @@ -10346,7 +10487,7 @@ dependencies = [ "fixed-hash 0.8.0", "futures", "hex", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "move-binary-format", "move-bytecode-utils", "move-core-types", @@ -10380,7 +10521,7 @@ dependencies = [ "ethers", "fastcrypto", "futures", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "log", "move-command-line-common", "move-core-types", @@ -10406,6 +10547,7 @@ dependencies = [ "accumulator", "anyhow", "async-trait", + "axum 0.7.5", "bcs", "chrono", "clap 4.5.8", @@ -10415,8 +10557,7 @@ dependencies = [ "fastcrypto", "futures", "hex", - "hyper 0.14.28", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "lazy_static 1.5.0", "log", "move-binary-format", @@ -10454,7 +10595,7 @@ dependencies = [ "tokio", "tonic", "tower", - "tower-http", + "tower-http 0.5.2", "tracing", "tracing-subscriber", ] @@ -10473,7 +10614,7 @@ dependencies = [ "derive_builder 0.20.0", "fastcrypto", "futures", - "jsonrpsee 0.16.3", + "jsonrpsee 0.23.2", "log", "move-core-types", "move-resource-viewer", @@ -10607,6 +10748,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "route-recognizer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" + [[package]] name = "rpassword" version = "7.3.1" @@ -10850,6 +10997,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls" +version = "0.23.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +dependencies = [ + "log", + "once_cell", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki 0.102.4", + "subtle", + "zeroize", +] + [[package]] name = "rustls-acme" version = "0.8.1" @@ -10859,7 +11021,7 @@ dependencies = [ "async-io", "async-trait", "async-web-client", - "axum-server", + "axum-server 0.5.1", "base64 0.13.1", "blocking", "chrono", @@ -10891,6 +11053,19 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rustls-native-certs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" +dependencies = [ + "openssl-probe", + "rustls-pemfile 2.1.2", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -10916,6 +11091,33 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +[[package]] +name = "rustls-platform-verifier" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e3beb939bcd33c269f4bf946cc829fcd336370267c4a927ac0399c84a3151a1" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls 0.23.10", + "rustls-native-certs 0.7.0", + "rustls-platform-verifier-android", + "rustls-webpki 0.102.4", + "security-framework", + "security-framework-sys", + "webpki-roots 0.26.1", + "winapi", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84e217e7fdc8466b5b35d30f8c0a30febd29173df4a3a0c2115d306b9c4117ad" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -11212,6 +11414,7 @@ dependencies = [ "core-foundation", "core-foundation-sys", "libc", + "num-bigint", "security-framework-sys", ] @@ -11937,13 +12140,28 @@ dependencies = [ "base64 0.13.1", "bytes", "futures", - "http 0.2.12", "httparse", "log", "rand 0.8.5", "sha-1", ] +[[package]] +name = "soketto" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37468c595637c10857701c990f93a40ce0e357cedb0953d1c26c8d8027f9bb53" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures", + "http 1.1.0", + "httparse", + "log", + "rand 0.8.5", + "sha1", +] + [[package]] name = "solang-parser" version = "0.3.3" @@ -12193,6 +12411,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "synstructure" version = "0.12.6" @@ -12692,6 +12916,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls 0.23.10", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-socks" version = "0.5.1" @@ -12713,6 +12948,7 @@ dependencies = [ "futures-core", "pin-project-lite", "tokio", + "tokio-util", ] [[package]] @@ -12862,7 +13098,7 @@ checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.6.20", "base64 0.13.1", "bytes", "flate2", @@ -12922,7 +13158,31 @@ dependencies = [ "futures-util", "http 0.2.12", "http-body 0.4.6", - "http-range-header", + "http-range-header 0.3.1", + "mime", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" +dependencies = [ + "async-compression", + "base64 0.21.7", + "bitflags 2.5.0", + "bytes", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "http-range-header 0.4.1", "httpdate", "iri-string", "mime", diff --git a/Cargo.toml b/Cargo.toml index 2db60f4261..ab9c4b1541 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,7 +159,7 @@ futures = "0.3.28" hex = "0.4.3" rustc-hex = "2.1" itertools = "0.13.0" -jsonrpsee = { version = "0.16.3", features = ["full"] } +jsonrpsee = { version = "0.23.2", features = ["full"] } jpst = "0.1.1" lazy_static = "1.5.0" linked-hash-map = "0.5.6" @@ -218,7 +218,7 @@ walkdir = "2.3.3" rocksdb = { version = "0.22.0", features = ["snappy", "lz4", "zstd", "zlib"], default-features = false } prometheus = "0.13.3" coarsetime = "0.1.22" -hyper = { version = "0.14.12", features = ["full"] } +hyper = { version = "1.3.1", features = ["full"] } num_enum = "0.7.2" libc = "^0.2" include_dir = { version = "0.6.2" } @@ -226,8 +226,8 @@ nostr = "0.22" serde-reflection = "0.3.6" serde-generate = "0.25.1" bcs-ext = { path = "moveos/moveos-commons/bcs_ext" } -tower = { version = "0.4.12", features = ["full", "util", "timeout", "load-shed", "limit"] } -tower-http = { version = "0.4.4", features = ["cors", "full", "trace", "set-header", "propagate-header"] } +tower = { version = "0.4.13", features = ["full", "util", "timeout", "load-shed", "limit"] } +tower-http = { version = "0.5.2", features = ["cors", "full", "trace", "set-header", "propagate-header"] } mirai-annotations = "1.12.0" lru = "0.11.0" bs58 = "0.5.1" @@ -251,8 +251,7 @@ diesel = { version = "2.2.1", features = [ ] } diesel-derive-enum = { version = "2.1.0", features = ["sqlite"] } diesel_migrations = { version = "2.2.0" } -axum = { version = "0.6.6", default-features = false, features = [ - "headers", +axum = { version = "0.7.5", default-features = false, features = [ "tokio", "http1", "http2", @@ -263,8 +262,8 @@ axum = { version = "0.6.6", default-features = false, features = [ "query", "ws", ] } -axum-extra = "0.4.2" -axum-server = { version = "0.5.1", default-features = false, features = [ +axum-extra = "0.9.3" +axum-server = { version = "0.6.0", default-features = false, features = [ "tls-rustls", ] } serenity = { version = "0.12.2", default-features = false, features = [ diff --git a/crates/rooch-faucet/Cargo.toml b/crates/rooch-faucet/Cargo.toml index e939241dc9..4218d5b105 100644 --- a/crates/rooch-faucet/Cargo.toml +++ b/crates/rooch-faucet/Cargo.toml @@ -20,6 +20,7 @@ serenity = { features = [ "model", ], workspace = true } axum = { workspace = true } +axum-server = { workspace = true } tracing = { workspace = true} tower = { workspace = true } tower-http = { workspace = true } diff --git a/crates/rooch-faucet/src/web.rs b/crates/rooch-faucet/src/web.rs index 07ffb99ffe..14bca223c0 100644 --- a/crates/rooch-faucet/src/web.rs +++ b/crates/rooch-faucet/src/web.rs @@ -90,7 +90,7 @@ pub async fn serve(app: App, web_config: WebConfig) -> Result<(), anyhow::Error> let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), web_config.port); - axum::Server::bind(&addr) + axum_server::bind(addr) .serve(router.into_make_service()) .await?; diff --git a/crates/rooch-rpc-client/src/client_config.rs b/crates/rooch-rpc-client/src/client_config.rs index 82121e2ff5..46a3a85f5a 100644 --- a/crates/rooch-rpc-client/src/client_config.rs +++ b/crates/rooch-rpc-client/src/client_config.rs @@ -77,7 +77,6 @@ impl Env { pub async fn create_rpc_client( &self, request_timeout: std::time::Duration, - max_concurrent_requests: Option, ) -> Result { let mut builder = ClientBuilder::default(); builder = builder.request_timeout(request_timeout); @@ -85,10 +84,6 @@ impl Env { builder = builder.ws_url(ws_url); } - if let Some(max_concurrent_requests) = max_concurrent_requests { - builder = builder.max_concurrent_requests(max_concurrent_requests as usize); - } - builder.build(&self.rpc).await } diff --git a/crates/rooch-rpc-client/src/lib.rs b/crates/rooch-rpc-client/src/lib.rs index 8e0929faff..0e0bfd30e0 100644 --- a/crates/rooch-rpc-client/src/lib.rs +++ b/crates/rooch-rpc-client/src/lib.rs @@ -25,7 +25,6 @@ pub mod wallet_context; pub struct ClientBuilder { request_timeout: Duration, - max_concurrent_requests: usize, ws_url: Option, } @@ -35,11 +34,6 @@ impl ClientBuilder { self } - pub fn max_concurrent_requests(mut self, max_concurrent_requests: usize) -> Self { - self.max_concurrent_requests = max_concurrent_requests; - self - } - pub fn ws_url(mut self, url: impl AsRef) -> Self { self.ws_url = Some(url.as_ref().to_string()); self @@ -50,8 +44,7 @@ impl ClientBuilder { let http_client = Arc::new( HttpClientBuilder::default() - .max_request_body_size(2 << 30) - .max_concurrent_requests(self.max_concurrent_requests) + .max_request_size(2 << 30) .request_timeout(self.request_timeout) .build(http)?, ); @@ -67,7 +60,6 @@ impl Default for ClientBuilder { fn default() -> Self { Self { request_timeout: Duration::from_secs(60), - max_concurrent_requests: 256, ws_url: None, } } diff --git a/crates/rooch-rpc-client/src/wallet_context.rs b/crates/rooch-rpc-client/src/wallet_context.rs index 14e4376f8d..e6d4c469f5 100644 --- a/crates/rooch-rpc-client/src/wallet_context.rs +++ b/crates/rooch-rpc-client/src/wallet_context.rs @@ -118,7 +118,7 @@ impl WalletContext { let client = self .client_config .get_active_env()? - .create_rpc_client(Duration::from_secs(DEFAULT_EXPIRATION_SECS), None) + .create_rpc_client(Duration::from_secs(DEFAULT_EXPIRATION_SECS)) .await?; self.client.write().await.insert(client).clone() diff --git a/crates/rooch-rpc-server/Cargo.toml b/crates/rooch-rpc-server/Cargo.toml index cacd85b196..3a6f81fee7 100644 --- a/crates/rooch-rpc-server/Cargo.toml +++ b/crates/rooch-rpc-server/Cargo.toml @@ -38,7 +38,7 @@ schemars = { workspace = true } serde_with = { workspace = true } rand = { workspace = true } fastcrypto = { workspace = true, features = ["copy_key"] } -hyper = { workspace = true } +axum = { workspace = true } log = { workspace = true } lazy_static = { workspace = true } rpassword = { workspace = true } @@ -68,4 +68,4 @@ rooch-indexer = { workspace = true } rooch-da = { workspace = true } rooch-framework = { workspace = true } rooch-genesis = { workspace = true } -rooch-db = { workspace = true } \ No newline at end of file +rooch-db = { workspace = true } diff --git a/crates/rooch-rpc-server/src/lib.rs b/crates/rooch-rpc-server/src/lib.rs index 398ab20bea..3098cccecb 100644 --- a/crates/rooch-rpc-server/src/lib.rs +++ b/crates/rooch-rpc-server/src/lib.rs @@ -4,14 +4,13 @@ use crate::server::btc_server::BtcServer; use crate::server::rooch_server::RoochServer; use crate::service::aggregate_service::AggregateService; -use crate::service::rpc_logger::RpcLogger; use crate::service::rpc_service::RpcService; use anyhow::{ensure, Error, Result}; +use axum::http::{HeaderValue, Method}; use coerce::actor::scheduler::timer::Timer; use coerce::actor::{system::ActorSystem, IntoActor}; -use hyper::header::HeaderValue; -use hyper::Method; use jsonrpsee::server::ServerBuilder; +use jsonrpsee::types::{ErrorObject, ErrorObjectOwned}; use jsonrpsee::RpcModule; use raw_store::errors::RawStoreError; use rooch_config::server_config::ServerConfig; @@ -327,7 +326,7 @@ pub async fn run_start_server(opt: RoochOpt, server_opt: ServerOpt) -> Result Result Result>(); - let handle = server.start(rpc_module_builder.module)?; + let handle = server.start(rpc_module_builder.module); info!("JSON-RPC HTTP Server start listening {:?}", addr); info!("Available JSON-RPC methods : {:?}", methods_names); @@ -369,8 +367,8 @@ fn _build_rpc_api(mut rpc_module: RpcModule) -> Rpc available_methods.sort(); rpc_module - .register_method("rpc_methods", move |_, _| { - Ok(json!({ + .register_method("rpc_methods", move |_, _, _| { + Ok::(json!({ "methods": available_methods, })) }) @@ -378,3 +376,7 @@ fn _build_rpc_api(mut rpc_module: RpcModule) -> Rpc rpc_module } + +pub fn err_obj(str: String) -> ErrorObjectOwned { + ErrorObject::owned(1, str, None::<()>) +} diff --git a/crates/rooch-rpc-server/src/server/btc_server.rs b/crates/rooch-rpc-server/src/server/btc_server.rs index 25adb6af16..2cfb739f50 100644 --- a/crates/rooch-rpc-server/src/server/btc_server.rs +++ b/crates/rooch-rpc-server/src/server/btc_server.rs @@ -1,6 +1,7 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 +use crate::err_obj; use crate::service::{aggregate_service::AggregateService, rpc_service::RpcService}; use anyhow::Result; use jsonrpsee::{ @@ -54,20 +55,23 @@ impl BtcAPIServer for BtcServer { _ => AccountAddress::ZERO.into(), }; - let global_state_filter = - UTXOFilterView::into_global_state_filter(filter, resolve_address)?; + let global_state_filter = UTXOFilterView::into_global_state_filter(filter, resolve_address) + .map_err(|e| err_obj(e.to_string()))?; let states = self .rpc_service .query_object_states(global_state_filter, cursor, limit_of + 1, descending_order) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let mut data = self .aggregate_service .build_utxos(states) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(|v| UTXOStateView::try_new_from_utxo_state(v, self.btc_network)) - .collect::, _>>()?; + .collect::, _>>() + .map_err(|e| err_obj(e.to_string()))?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); @@ -102,19 +106,23 @@ impl BtcAPIServer for BtcServer { }; let global_state_filter = - InscriptionFilterView::into_global_state_filter(filter, resolve_address)?; + InscriptionFilterView::into_global_state_filter(filter, resolve_address) + .map_err(|e| err_obj(e.to_string()))?; let states = self .rpc_service .query_object_states(global_state_filter, cursor, limit_of + 1, descending_order) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let mut data = self .aggregate_service .build_inscriptions(states) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(|v| InscriptionStateView::try_new_from_inscription_state(v, self.btc_network)) - .collect::, _>>()?; + .collect::, _>>() + .map_err(|e| err_obj(e.to_string()))?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index e9b0fbd83b..3eae79417f 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -1,6 +1,7 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 +use crate::err_obj; use crate::service::aggregate_service::AggregateService; use crate::service::rpc_service::RpcService; use anyhow::Result; @@ -154,18 +155,25 @@ impl RoochServer { #[async_trait] impl RoochAPIServer for RoochServer { async fn get_chain_id(&self) -> RpcResult> { - let chain_id = self.rpc_service.get_chain_id().await?; + let chain_id = self + .rpc_service + .get_chain_id() + .await + .map_err(|e| err_obj(e.to_string()))?; Ok(StrView(chain_id)) } async fn send_raw_transaction(&self, payload: BytesView) -> RpcResult { info!("send_raw_transaction payload: {:?}", payload); let mut tx = - bcs::from_bytes::(&payload.0).map_err(anyhow::Error::from)?; + bcs::from_bytes::(&payload.0).map_err(|e| err_obj(e.to_string()))?; info!("send_raw_transaction tx: {:?}", tx); let hash = tx.tx_hash(); - self.rpc_service.queue_tx(tx).await?; + self.rpc_service + .queue_tx(tx) + .await + .map_err(|e| err_obj(e.to_string()))?; Ok(hash.into()) } @@ -175,8 +183,13 @@ impl RoochAPIServer for RoochServer { tx_options: Option, ) -> RpcResult { let tx_options = tx_options.unwrap_or_default(); - let tx = bcs::from_bytes::(&payload.0).map_err(anyhow::Error::from)?; - let tx_response = self.rpc_service.execute_tx(tx).await?; + let tx = + bcs::from_bytes::(&payload.0).map_err(|e| err_obj(e.to_string()))?; + let tx_response = self + .rpc_service + .execute_tx(tx) + .await + .map_err(|e| err_obj(e.to_string()))?; let result = if tx_options.with_output { ExecuteTransactionResponseView::from(tx_response) @@ -193,7 +206,8 @@ impl RoochAPIServer for RoochServer { Ok(self .rpc_service .execute_view_function(function_call.into()) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into()) } @@ -211,13 +225,15 @@ impl RoochAPIServer for RoochServer { let states = self .rpc_service .get_annotated_states(access_path.into()) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; if show_display { let valid_states = states.iter().filter_map(|s| s.as_ref()).collect::>(); let mut valid_display_field_views = self .get_display_fields_and_render(valid_states, is_object) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; valid_display_field_views.reverse(); states .into_iter() @@ -238,7 +254,8 @@ impl RoochAPIServer for RoochServer { } else { self.rpc_service .get_states(access_path.into()) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(|s| s.map(StateView::from)) .collect() @@ -262,7 +279,9 @@ impl RoochAPIServer for RoochServer { MAX_RESULT_LIMIT_USIZE, ); let cursor_of = match cursor.clone() { - Some(key_state_str) => Some(KeyState::from_str(key_state_str.as_str())?), + Some(key_state_str) => Some( + KeyState::from_str(key_state_str.as_str()).map_err(|e| err_obj(e.to_string()))?, + ), None => None, }; let mut data: Vec = if state_option.decode || show_display { @@ -270,14 +289,16 @@ impl RoochAPIServer for RoochServer { let (key_states, states): (Vec, Vec) = self .rpc_service .list_annotated_states(access_path.into(), cursor_of, limit_of + 1) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .unzip(); let state_refs: Vec<&AnnotatedState> = states.iter().collect(); if show_display { let display_field_views = self .get_display_fields_and_render(state_refs, is_object) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; key_states .into_iter() .zip(states) @@ -301,7 +322,8 @@ impl RoochAPIServer for RoochServer { } else { self.rpc_service .list_states(access_path.into(), cursor_of, limit_of + 1) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(|(key_state, state)| { StateKVView::new(KeyStateHexView::from(key_state), StateView::from(state)) @@ -334,13 +356,17 @@ impl RoochAPIServer for RoochServer { let show_display = state_option.show_display; let objects_view = if decode || show_display { - let states: Vec> = - self.rpc_service.get_annotated_states(access_path).await?; + let states: Vec> = self + .rpc_service + .get_annotated_states(access_path) + .await + .map_err(|e| err_obj(e.to_string()))?; let mut valid_display_field_views = if show_display { let valid_states = states.iter().filter_map(|s| s.as_ref()).collect::>(); self.get_display_fields_and_render(valid_states, true) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? } else { vec![] }; @@ -362,7 +388,8 @@ impl RoochAPIServer for RoochServer { }) .transpose() }) - .collect::>>()?; + .collect::>>() + .map_err(|e| err_obj(e.to_string()))?; if show_display { valid_display_field_views.reverse(); @@ -385,7 +412,8 @@ impl RoochAPIServer for RoochServer { } else { self.rpc_service .get_states(access_path) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(|s| { s.map(|s| { @@ -401,8 +429,16 @@ impl RoochAPIServer for RoochServer { .iter() .filter_map(|o| o.as_ref().map(|s| s.owner.into())) .collect::>(); - let btc_network = self.rpc_service.get_bitcoin_network().await?; - let address_mapping = self.rpc_service.get_bitcoin_addresses(addresses).await?; + let btc_network = self + .rpc_service + .get_bitcoin_network() + .await + .map_err(|e| err_obj(e.to_string()))?; + let address_mapping = self + .rpc_service + .get_bitcoin_addresses(addresses) + .await + .map_err(|e| err_obj(e.to_string()))?; let objects_view = objects_view .into_iter() @@ -414,12 +450,14 @@ impl RoochAPIServer for RoochServer { .expect("should exist.") .clone() .map(|a| a.format(btc_network)) - .transpose()?; + .transpose() + .map_err(|e| err_obj(e.to_string()))?; Ok(s.with_owner_bitcoin_address(bitcoin_address)) }) .transpose() }) - .collect::>>()?; + .collect::>>() + .map_err(|e| err_obj(e.to_string()))?; Ok(objects_view) } @@ -447,7 +485,8 @@ impl RoochAPIServer for RoochServer { limit, descending_order, ) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(EventView::from) .collect::>() @@ -459,7 +498,8 @@ impl RoochAPIServer for RoochServer { limit, descending_order, ) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(EventView::from) .collect::>() @@ -485,11 +525,16 @@ impl RoochAPIServer for RoochServer { ) -> RpcResult>> { let tx_hashes: Vec = tx_hashes.iter().map(|m| (*m).into()).collect::>(); - let bitcoin_network = self.rpc_service.get_bitcoin_network().await?; + let bitcoin_network = self + .rpc_service + .get_bitcoin_network() + .await + .map_err(|e| err_obj(e.to_string()))?; let data = self .aggregate_service .get_transaction_with_info(tx_hashes) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let rooch_addresses = data .iter() @@ -498,7 +543,8 @@ impl RoochAPIServer for RoochServer { let address_mapping = self .rpc_service .get_bitcoin_addresses(rooch_addresses) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let data = data .into_iter() @@ -511,7 +557,8 @@ impl RoochAPIServer for RoochServer { None => None, } .flatten() - .transpose()?; + .transpose() + .map_err(|e| err_obj(e.to_string()))?; Ok(TransactionWithInfoView::new_from_transaction_with_info( tx, sender_bitcoin_address, @@ -519,7 +566,8 @@ impl RoochAPIServer for RoochServer { }) .transpose() }) - .collect::>>()?; + .collect::>>() + .map_err(|e| err_obj(e.to_string()))?; Ok(data) } @@ -530,7 +578,11 @@ impl RoochAPIServer for RoochServer { limit: Option>, descending_order: Option, ) -> RpcResult { - let last_sequencer_order = self.rpc_service.get_sequencer_order().await?; + let last_sequencer_order = self + .rpc_service + .get_sequencer_order() + .await + .map_err(|e| err_obj(e.to_string()))?; let limit_of = min( limit @@ -553,18 +605,20 @@ impl RoochAPIServer for RoochServer { (end..start).rev().collect::>() } else { let start = cursor.unwrap_or(0); - let start_plus = - start - .checked_add(limit_of + 1) - .ok_or(jsonrpsee::core::Error::Custom( - "cursor value is overflow".to_string(), - ))?; + let start_plus = start + .checked_add(limit_of + 1) + .ok_or(err_obj("cursor value is overflow".to_string())) + .map_err(|e| err_obj(e.to_string()))?; let end = min(start_plus, last_sequencer_order + 1); (start..end).collect::>() }; - let tx_hashs = self.rpc_service.get_tx_hashs(tx_orders.clone()).await?; + let tx_hashs = self + .rpc_service + .get_tx_hashs(tx_orders.clone()) + .await + .map_err(|e| err_obj(e.to_string()))?; let mut hash_order_pair = tx_hashs .into_iter() @@ -585,12 +639,16 @@ impl RoochAPIServer for RoochServer { .map(|(h, _o)| h) .collect::>(), ) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .flatten() .collect::>(); - let data = self.transactions_to_view(data).await?; + let data = self + .transactions_to_view(data) + .await + .map_err(|e| err_obj(e.to_string()))?; Ok(TransactionWithInfoPageView { data, @@ -608,7 +666,8 @@ impl RoochAPIServer for RoochServer { .aggregate_service .get_balance(account_addr.into(), coin_type.into()) .await - .map(Into::into)?) + .map(Into::into) + .map_err(|e| err_obj(e.to_string()))?) } /// get account balances by RoochAddress @@ -625,7 +684,8 @@ impl RoochAPIServer for RoochServer { let mut data = self .aggregate_service .get_balances(account_addr.into(), cursor, limit_of + 1) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); @@ -664,17 +724,22 @@ impl RoochAPIServer for RoochServer { let txs = self .rpc_service .query_transactions(filter.into(), cursor, limit_of + 1, descending_order) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let mut data = self .aggregate_service .build_transaction_with_infos(txs) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); - let data = self.transactions_to_view(data).await?; + let data = self + .transactions_to_view(data) + .await + .map_err(|e| err_obj(e.to_string()))?; let next_cursor = data .last() @@ -706,7 +771,8 @@ impl RoochAPIServer for RoochServer { let mut data = self .rpc_service .query_events(filter.into(), cursor, limit_of + 1, descending_order) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(IndexerEventView::from) .collect::>(); @@ -741,11 +807,13 @@ impl RoochAPIServer for RoochServer { let descending_order = query_option.descending; let decode = query_option.decode; - let global_state_filter = ObjectStateFilterView::try_into_object_state_filter(filter)?; + let global_state_filter = ObjectStateFilterView::try_into_object_state_filter(filter) + .map_err(|e| err_obj(e.to_string()))?; let states = self .rpc_service .query_object_states(global_state_filter, cursor, limit_of + 1, descending_order) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; let object_ids = states .iter() @@ -755,7 +823,8 @@ impl RoochAPIServer for RoochServer { let annotated_states = self .rpc_service .get_annotated_states(access_path) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_iter() .map(|s| s.expect("object should exist!")) // TODO: is statedb always synced with indexer? .collect::>(); @@ -764,7 +833,8 @@ impl RoochAPIServer for RoochServer { let valid_states = annotated_states.iter().collect::>(); let valid_display_field_views = self .get_display_fields_and_render(valid_states, true) - .await?; + .await + .map_err(|e| err_obj(e.to_string()))?; annotated_states .into_iter() .zip(valid_display_field_views) @@ -790,15 +860,21 @@ impl RoochAPIServer for RoochServer { .collect::>() }; - let network = self.rpc_service.get_bitcoin_network().await?; + let network = self + .rpc_service + .get_bitcoin_network() + .await + .map_err(|e| err_obj(e.to_string()))?; let rooch_addresses = states.iter().map(|s| s.owner).collect::>(); let bitcoin_addresses = self .rpc_service .get_bitcoin_addresses(rooch_addresses) - .await? + .await + .map_err(|e| err_obj(e.to_string()))? .into_values() .map(|btc_addr| btc_addr.map(|addr| addr.format(network)).transpose()) - .collect::>>>()?; + .collect::>>>() + .map_err(|e| err_obj(e.to_string()))?; let mut data = annotated_states_with_display .into_iter() diff --git a/crates/rooch-rpc-server/src/service/mod.rs b/crates/rooch-rpc-server/src/service/mod.rs index 02eaf7e980..3c8acd0439 100644 --- a/crates/rooch-rpc-server/src/service/mod.rs +++ b/crates/rooch-rpc-server/src/service/mod.rs @@ -2,5 +2,4 @@ // SPDX-License-Identifier: Apache-2.0 pub mod aggregate_service; -pub mod rpc_logger; pub mod rpc_service; diff --git a/crates/rooch-rpc-server/src/service/rpc_logger.rs b/crates/rooch-rpc-server/src/service/rpc_logger.rs deleted file mode 100644 index e043bae0e1..0000000000 --- a/crates/rooch-rpc-server/src/service/rpc_logger.rs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) RoochNetwork -// SPDX-License-Identifier: Apache-2.0 - -use jsonrpsee::server::logger::Logger; -use tracing::Level; - -#[derive(Debug, Clone)] -pub struct RpcLogger; - -impl Logger for RpcLogger { - type Instant = std::time::Instant; - - fn on_connect( - &self, - _remote_addr: std::net::SocketAddr, - _request: &jsonrpsee::server::logger::HttpRequest, - _t: jsonrpsee::server::logger::TransportProtocol, - ) { - } - - fn on_request( - &self, - _transport: jsonrpsee::server::logger::TransportProtocol, - ) -> Self::Instant { - std::time::Instant::now() - } - - fn on_call( - &self, - method_name: &str, - params: jsonrpsee::types::Params, - _kind: jsonrpsee::server::logger::MethodKind, - transport: jsonrpsee::server::logger::TransportProtocol, - ) { - //TODO remove param parse when server stable. - let params_str = match params.parse::() { - Ok(json) => json.to_string(), - Err(e) => e.to_string(), - }; - tracing::event!( - Level::INFO, - event = "on_call", - transport = transport.to_string(), - method_name = method_name, - params = params_str, - ); - } - - fn on_result( - &self, - method_name: &str, - success: bool, - started_at: Self::Instant, - _transport: jsonrpsee::server::logger::TransportProtocol, - ) { - let elapsed_millis = started_at.elapsed().as_millis(); - tracing::event!( - Level::INFO, - event = "on_result", - method_name = method_name, - success = success, - elapsed_millis = elapsed_millis - ); - } - - fn on_response( - &self, - _result: &str, - _started_at: Self::Instant, - _transport: jsonrpsee::server::logger::TransportProtocol, - ) { - } - - fn on_disconnect( - &self, - _remote_addr: std::net::SocketAddr, - _transport: jsonrpsee::server::logger::TransportProtocol, - ) { - } -} diff --git a/crates/rooch/src/commands/env/commands/add.rs b/crates/rooch/src/commands/env/commands/add.rs index 6096a3aae0..fc8447b647 100644 --- a/crates/rooch/src/commands/env/commands/add.rs +++ b/crates/rooch/src/commands/env/commands/add.rs @@ -31,7 +31,7 @@ impl AddCommand { }; // TODO: is this request timeout okay? - env.create_rpc_client(Duration::from_secs(5), None).await?; + env.create_rpc_client(Duration::from_secs(5)).await?; context.client_config.add_env(env); context.client_config.save()?; diff --git a/frameworks/bitcoin-move/src/natives/ord/inscription.rs b/frameworks/bitcoin-move/src/natives/ord/inscription.rs index f35ee74487..6bc14197a2 100644 --- a/frameworks/bitcoin-move/src/natives/ord/inscription.rs +++ b/frameworks/bitcoin-move/src/natives/ord/inscription.rs @@ -12,7 +12,7 @@ use { super::envelope, super::inscription_id::InscriptionId, super::media::Media, - axum::http::header::HeaderValue, + axum::http::HeaderValue, bitcoin::{ blockdata::{ opcodes, From 649c0432af5d8d86037b0d4d5e4c5d0d6648784c Mon Sep 17 00:00:00 2001 From: vegetabledogdog Date: Tue, 2 Jul 2024 00:29:07 +0800 Subject: [PATCH 2/4] [deps] restore hyper --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a32465668c..a45f1d8475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6275,7 +6275,7 @@ version = "0.5.7" dependencies = [ "anyhow", "futures", - "hyper 1.3.1", + "hyper 0.14.28", "log", "prometheus", "psutil", @@ -9813,7 +9813,7 @@ dependencies = [ "fastcrypto", "futures", "hex", - "hyper 1.3.1", + "hyper 0.14.28", "lazy_static 1.5.0", "log", "move-binary-format", diff --git a/Cargo.toml b/Cargo.toml index ab9c4b1541..9066fdcc77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -218,7 +218,7 @@ walkdir = "2.3.3" rocksdb = { version = "0.22.0", features = ["snappy", "lz4", "zstd", "zlib"], default-features = false } prometheus = "0.13.3" coarsetime = "0.1.22" -hyper = { version = "1.3.1", features = ["full"] } +hyper = { version = "0.14.12", features = ["full"] } num_enum = "0.7.2" libc = "^0.2" include_dir = { version = "0.6.2" } From 6b6d38650b3a6ea5b87e1608a54d5645016fbc6e Mon Sep 17 00:00:00 2001 From: vegetabledogdog Date: Tue, 2 Jul 2024 15:14:56 +0800 Subject: [PATCH 3/4] [deps] refactor --- crates/rooch-rpc-api/src/api/btc_api.rs | 2 +- crates/rooch-rpc-api/src/api/rooch_api.rs | 2 +- crates/rooch-rpc-api/src/lib.rs | 31 +++ crates/rooch-rpc-client/src/client_config.rs | 4 +- crates/rooch-rpc-server/src/lib.rs | 13 +- .../rooch-rpc-server/src/server/btc_server.rs | 32 ++- .../src/server/rooch_server.rs | 183 +++++------------- crates/rooch-rpc-server/src/service/mod.rs | 1 + .../src/service/rpc_logger.rs | 31 +++ 9 files changed, 137 insertions(+), 162 deletions(-) create mode 100644 crates/rooch-rpc-server/src/service/rpc_logger.rs diff --git a/crates/rooch-rpc-api/src/api/btc_api.rs b/crates/rooch-rpc-api/src/api/btc_api.rs index 67ad8f4225..da4cdabf25 100644 --- a/crates/rooch-rpc-api/src/api/btc_api.rs +++ b/crates/rooch-rpc-api/src/api/btc_api.rs @@ -4,7 +4,7 @@ use crate::jsonrpc_types::btc::ord::InscriptionFilterView; use crate::jsonrpc_types::btc::utxo::UTXOFilterView; use crate::jsonrpc_types::{InscriptionPageView, StrView, UTXOPageView}; -use jsonrpsee::core::RpcResult; +use crate::RpcResult; use jsonrpsee::proc_macros::rpc; use rooch_open_rpc_macros::open_rpc; use rooch_types::indexer::state::IndexerStateID; diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs index 9db8876188..d402a5bad4 100644 --- a/crates/rooch-rpc-api/src/api/rooch_api.rs +++ b/crates/rooch-rpc-api/src/api/rooch_api.rs @@ -12,7 +12,7 @@ use crate::jsonrpc_types::{ ObjectIDView, ObjectStateFilterView, ObjectStateView, QueryOptions, StateOptions, StatePageView, StateView, StrView, StructTagView, TransactionWithInfoPageView, TxOptions, }; -use jsonrpsee::core::RpcResult; +use crate::RpcResult; use jsonrpsee::proc_macros::rpc; use moveos_types::{access_path::AccessPath, state::KeyState}; use rooch_open_rpc_macros::open_rpc; diff --git a/crates/rooch-rpc-api/src/lib.rs b/crates/rooch-rpc-api/src/lib.rs index 9376e363f3..49721b27ac 100644 --- a/crates/rooch-rpc-api/src/lib.rs +++ b/crates/rooch-rpc-api/src/lib.rs @@ -5,3 +5,34 @@ pub mod api; pub mod jsonrpc_types; + +pub type RpcResult = Result; +use jsonrpsee::types::{ErrorObject, ErrorObjectOwned}; +use rooch_types::error::RoochError; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum RpcError { + #[error(transparent)] + RoochError(#[from] RoochError), + + #[error(transparent)] + InternalError(#[from] anyhow::Error), + + #[error("Deserialization error: {0}")] + BcsError(#[from] bcs::Error), + + #[error("Unexpected error: {0}")] + UnexpectedError(String), +} + +impl From for ErrorObjectOwned { + fn from(err: RpcError) -> Self { + match err { + RpcError::RoochError(err) => ErrorObject::owned(1, err.to_string(), None::<()>), + RpcError::InternalError(err) => ErrorObject::owned(2, err.to_string(), None::<()>), + RpcError::BcsError(err) => ErrorObject::owned(3, err.to_string(), None::<()>), + RpcError::UnexpectedError(err) => ErrorObject::owned(4, err.to_string(), None::<()>), + } + } +} diff --git a/crates/rooch-rpc-client/src/client_config.rs b/crates/rooch-rpc-client/src/client_config.rs index 46a3a85f5a..1cf9314437 100644 --- a/crates/rooch-rpc-client/src/client_config.rs +++ b/crates/rooch-rpc-client/src/client_config.rs @@ -14,8 +14,8 @@ use std::fmt::{Display, Formatter, Write}; use std::path::PathBuf; pub const DEFAULT_EXPIRATION_SECS: u64 = 30; -pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network:443/"; -pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network:443/"; +pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network/"; +pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network/"; #[derive(Serialize, Deserialize, Debug)] pub struct ClientConfig { diff --git a/crates/rooch-rpc-server/src/lib.rs b/crates/rooch-rpc-server/src/lib.rs index 3098cccecb..8cd82038ad 100644 --- a/crates/rooch-rpc-server/src/lib.rs +++ b/crates/rooch-rpc-server/src/lib.rs @@ -4,13 +4,14 @@ use crate::server::btc_server::BtcServer; use crate::server::rooch_server::RoochServer; use crate::service::aggregate_service::AggregateService; +use crate::service::rpc_logger::RpcLogger; use crate::service::rpc_service::RpcService; use anyhow::{ensure, Error, Result}; use axum::http::{HeaderValue, Method}; use coerce::actor::scheduler::timer::Timer; use coerce::actor::{system::ActorSystem, IntoActor}; +use jsonrpsee::server::middleware::rpc::RpcServiceBuilder; use jsonrpsee::server::ServerBuilder; -use jsonrpsee::types::{ErrorObject, ErrorObjectOwned}; use jsonrpsee::RpcModule; use raw_store::errors::RawStoreError; use rooch_config::server_config::ServerConfig; @@ -33,6 +34,7 @@ use rooch_proposer::proxy::ProposerProxy; use rooch_relayer::actor::messages::RelayTick; use rooch_relayer::actor::relayer::RelayerActor; use rooch_rpc_api::api::RoochRpcModule; +use rooch_rpc_api::RpcError; use rooch_sequencer::actor::sequencer::SequencerActor; use rooch_sequencer::proxy::SequencerProxy; use rooch_types::address::RoochAddress; @@ -334,9 +336,12 @@ pub async fn run_start_server(opt: RoochOpt, server_opt: ServerOpt) -> Result(mut rpc_module: RpcModule) -> Rpc rpc_module .register_method("rpc_methods", move |_, _, _| { - Ok::(json!({ + Ok::(json!({ "methods": available_methods, })) }) @@ -376,7 +381,3 @@ fn _build_rpc_api(mut rpc_module: RpcModule) -> Rpc rpc_module } - -pub fn err_obj(str: String) -> ErrorObjectOwned { - ErrorObject::owned(1, str, None::<()>) -} diff --git a/crates/rooch-rpc-server/src/server/btc_server.rs b/crates/rooch-rpc-server/src/server/btc_server.rs index 2cfb739f50..71d4d57d15 100644 --- a/crates/rooch-rpc-server/src/server/btc_server.rs +++ b/crates/rooch-rpc-server/src/server/btc_server.rs @@ -1,19 +1,16 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 -use crate::err_obj; use crate::service::{aggregate_service::AggregateService, rpc_service::RpcService}; use anyhow::Result; -use jsonrpsee::{ - core::{async_trait, RpcResult}, - RpcModule, -}; +use jsonrpsee::{core::async_trait, RpcModule}; use move_core_types::account_address::AccountAddress; use rooch_rpc_api::api::btc_api::BtcAPIServer; use rooch_rpc_api::api::{RoochRpcModule, DEFAULT_RESULT_LIMIT_USIZE, MAX_RESULT_LIMIT_USIZE}; use rooch_rpc_api::jsonrpc_types::btc::ord::{InscriptionFilterView, InscriptionStateView}; use rooch_rpc_api::jsonrpc_types::btc::utxo::{UTXOFilterView, UTXOStateView}; use rooch_rpc_api::jsonrpc_types::{InscriptionPageView, StrView, UTXOPageView}; +use rooch_rpc_api::RpcResult; use rooch_types::indexer::state::IndexerStateID; use std::cmp::min; @@ -55,23 +52,20 @@ impl BtcAPIServer for BtcServer { _ => AccountAddress::ZERO.into(), }; - let global_state_filter = UTXOFilterView::into_global_state_filter(filter, resolve_address) - .map_err(|e| err_obj(e.to_string()))?; + let global_state_filter = + UTXOFilterView::into_global_state_filter(filter, resolve_address)?; let states = self .rpc_service .query_object_states(global_state_filter, cursor, limit_of + 1, descending_order) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let mut data = self .aggregate_service .build_utxos(states) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(|v| UTXOStateView::try_new_from_utxo_state(v, self.btc_network)) - .collect::, _>>() - .map_err(|e| err_obj(e.to_string()))?; + .collect::, _>>()?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); @@ -106,23 +100,19 @@ impl BtcAPIServer for BtcServer { }; let global_state_filter = - InscriptionFilterView::into_global_state_filter(filter, resolve_address) - .map_err(|e| err_obj(e.to_string()))?; + InscriptionFilterView::into_global_state_filter(filter, resolve_address)?; let states = self .rpc_service .query_object_states(global_state_filter, cursor, limit_of + 1, descending_order) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let mut data = self .aggregate_service .build_inscriptions(states) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(|v| InscriptionStateView::try_new_from_inscription_state(v, self.btc_network)) - .collect::, _>>() - .map_err(|e| err_obj(e.to_string()))?; + .collect::, _>>()?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index 3eae79417f..301b20c97c 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -1,14 +1,10 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 -use crate::err_obj; use crate::service::aggregate_service::AggregateService; use crate::service::rpc_service::RpcService; use anyhow::Result; -use jsonrpsee::{ - core::{async_trait, RpcResult}, - RpcModule, -}; +use jsonrpsee::{core::async_trait, RpcModule}; use moveos_types::{ access_path::AccessPath, h256::H256, @@ -34,6 +30,8 @@ use rooch_rpc_api::jsonrpc_types::{ ExecuteTransactionResponseView, FunctionCallView, H256View, StatePageView, StateView, StrView, StructTagView, TransactionWithInfoPageView, }; +use rooch_rpc_api::RpcError; +use rooch_rpc_api::RpcResult; use rooch_rpc_api::{api::rooch_api::RoochAPIServer, api::DEFAULT_RESULT_LIMIT}; use rooch_rpc_api::{ api::{RoochRpcModule, DEFAULT_RESULT_LIMIT_USIZE}, @@ -155,25 +153,17 @@ impl RoochServer { #[async_trait] impl RoochAPIServer for RoochServer { async fn get_chain_id(&self) -> RpcResult> { - let chain_id = self - .rpc_service - .get_chain_id() - .await - .map_err(|e| err_obj(e.to_string()))?; + let chain_id = self.rpc_service.get_chain_id().await?; Ok(StrView(chain_id)) } async fn send_raw_transaction(&self, payload: BytesView) -> RpcResult { info!("send_raw_transaction payload: {:?}", payload); - let mut tx = - bcs::from_bytes::(&payload.0).map_err(|e| err_obj(e.to_string()))?; + let mut tx = bcs::from_bytes::(&payload.0)?; info!("send_raw_transaction tx: {:?}", tx); let hash = tx.tx_hash(); - self.rpc_service - .queue_tx(tx) - .await - .map_err(|e| err_obj(e.to_string()))?; + self.rpc_service.queue_tx(tx).await?; Ok(hash.into()) } @@ -183,13 +173,8 @@ impl RoochAPIServer for RoochServer { tx_options: Option, ) -> RpcResult { let tx_options = tx_options.unwrap_or_default(); - let tx = - bcs::from_bytes::(&payload.0).map_err(|e| err_obj(e.to_string()))?; - let tx_response = self - .rpc_service - .execute_tx(tx) - .await - .map_err(|e| err_obj(e.to_string()))?; + let tx = bcs::from_bytes::(&payload.0)?; + let tx_response = self.rpc_service.execute_tx(tx).await?; let result = if tx_options.with_output { ExecuteTransactionResponseView::from(tx_response) @@ -206,8 +191,7 @@ impl RoochAPIServer for RoochServer { Ok(self .rpc_service .execute_view_function(function_call.into()) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into()) } @@ -225,15 +209,13 @@ impl RoochAPIServer for RoochServer { let states = self .rpc_service .get_annotated_states(access_path.into()) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; if show_display { let valid_states = states.iter().filter_map(|s| s.as_ref()).collect::>(); let mut valid_display_field_views = self .get_display_fields_and_render(valid_states, is_object) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; valid_display_field_views.reverse(); states .into_iter() @@ -254,8 +236,7 @@ impl RoochAPIServer for RoochServer { } else { self.rpc_service .get_states(access_path.into()) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(|s| s.map(StateView::from)) .collect() @@ -279,9 +260,7 @@ impl RoochAPIServer for RoochServer { MAX_RESULT_LIMIT_USIZE, ); let cursor_of = match cursor.clone() { - Some(key_state_str) => Some( - KeyState::from_str(key_state_str.as_str()).map_err(|e| err_obj(e.to_string()))?, - ), + Some(key_state_str) => Some(KeyState::from_str(key_state_str.as_str())?), None => None, }; let mut data: Vec = if state_option.decode || show_display { @@ -289,16 +268,14 @@ impl RoochAPIServer for RoochServer { let (key_states, states): (Vec, Vec) = self .rpc_service .list_annotated_states(access_path.into(), cursor_of, limit_of + 1) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .unzip(); let state_refs: Vec<&AnnotatedState> = states.iter().collect(); if show_display { let display_field_views = self .get_display_fields_and_render(state_refs, is_object) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; key_states .into_iter() .zip(states) @@ -322,8 +299,7 @@ impl RoochAPIServer for RoochServer { } else { self.rpc_service .list_states(access_path.into(), cursor_of, limit_of + 1) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(|(key_state, state)| { StateKVView::new(KeyStateHexView::from(key_state), StateView::from(state)) @@ -356,17 +332,13 @@ impl RoochAPIServer for RoochServer { let show_display = state_option.show_display; let objects_view = if decode || show_display { - let states: Vec> = self - .rpc_service - .get_annotated_states(access_path) - .await - .map_err(|e| err_obj(e.to_string()))?; + let states: Vec> = + self.rpc_service.get_annotated_states(access_path).await?; let mut valid_display_field_views = if show_display { let valid_states = states.iter().filter_map(|s| s.as_ref()).collect::>(); self.get_display_fields_and_render(valid_states, true) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? } else { vec![] }; @@ -388,8 +360,7 @@ impl RoochAPIServer for RoochServer { }) .transpose() }) - .collect::>>() - .map_err(|e| err_obj(e.to_string()))?; + .collect::>>()?; if show_display { valid_display_field_views.reverse(); @@ -412,8 +383,7 @@ impl RoochAPIServer for RoochServer { } else { self.rpc_service .get_states(access_path) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(|s| { s.map(|s| { @@ -429,16 +399,8 @@ impl RoochAPIServer for RoochServer { .iter() .filter_map(|o| o.as_ref().map(|s| s.owner.into())) .collect::>(); - let btc_network = self - .rpc_service - .get_bitcoin_network() - .await - .map_err(|e| err_obj(e.to_string()))?; - let address_mapping = self - .rpc_service - .get_bitcoin_addresses(addresses) - .await - .map_err(|e| err_obj(e.to_string()))?; + let btc_network = self.rpc_service.get_bitcoin_network().await?; + let address_mapping = self.rpc_service.get_bitcoin_addresses(addresses).await?; let objects_view = objects_view .into_iter() @@ -450,14 +412,12 @@ impl RoochAPIServer for RoochServer { .expect("should exist.") .clone() .map(|a| a.format(btc_network)) - .transpose() - .map_err(|e| err_obj(e.to_string()))?; + .transpose()?; Ok(s.with_owner_bitcoin_address(bitcoin_address)) }) .transpose() }) - .collect::>>() - .map_err(|e| err_obj(e.to_string()))?; + .collect::>>()?; Ok(objects_view) } @@ -485,8 +445,7 @@ impl RoochAPIServer for RoochServer { limit, descending_order, ) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(EventView::from) .collect::>() @@ -498,8 +457,7 @@ impl RoochAPIServer for RoochServer { limit, descending_order, ) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(EventView::from) .collect::>() @@ -525,16 +483,11 @@ impl RoochAPIServer for RoochServer { ) -> RpcResult>> { let tx_hashes: Vec = tx_hashes.iter().map(|m| (*m).into()).collect::>(); - let bitcoin_network = self - .rpc_service - .get_bitcoin_network() - .await - .map_err(|e| err_obj(e.to_string()))?; + let bitcoin_network = self.rpc_service.get_bitcoin_network().await?; let data = self .aggregate_service .get_transaction_with_info(tx_hashes) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let rooch_addresses = data .iter() @@ -543,8 +496,7 @@ impl RoochAPIServer for RoochServer { let address_mapping = self .rpc_service .get_bitcoin_addresses(rooch_addresses) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let data = data .into_iter() @@ -557,8 +509,7 @@ impl RoochAPIServer for RoochServer { None => None, } .flatten() - .transpose() - .map_err(|e| err_obj(e.to_string()))?; + .transpose()?; Ok(TransactionWithInfoView::new_from_transaction_with_info( tx, sender_bitcoin_address, @@ -566,8 +517,7 @@ impl RoochAPIServer for RoochServer { }) .transpose() }) - .collect::>>() - .map_err(|e| err_obj(e.to_string()))?; + .collect::>>()?; Ok(data) } @@ -578,11 +528,7 @@ impl RoochAPIServer for RoochServer { limit: Option>, descending_order: Option, ) -> RpcResult { - let last_sequencer_order = self - .rpc_service - .get_sequencer_order() - .await - .map_err(|e| err_obj(e.to_string()))?; + let last_sequencer_order = self.rpc_service.get_sequencer_order().await?; let limit_of = min( limit @@ -607,18 +553,15 @@ impl RoochAPIServer for RoochServer { let start = cursor.unwrap_or(0); let start_plus = start .checked_add(limit_of + 1) - .ok_or(err_obj("cursor value is overflow".to_string())) - .map_err(|e| err_obj(e.to_string()))?; + .ok_or(RpcError::UnexpectedError( + "cursor value is overflow".to_string(), + ))?; let end = min(start_plus, last_sequencer_order + 1); (start..end).collect::>() }; - let tx_hashs = self - .rpc_service - .get_tx_hashs(tx_orders.clone()) - .await - .map_err(|e| err_obj(e.to_string()))?; + let tx_hashs = self.rpc_service.get_tx_hashs(tx_orders.clone()).await?; let mut hash_order_pair = tx_hashs .into_iter() @@ -639,16 +582,12 @@ impl RoochAPIServer for RoochServer { .map(|(h, _o)| h) .collect::>(), ) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .flatten() .collect::>(); - let data = self - .transactions_to_view(data) - .await - .map_err(|e| err_obj(e.to_string()))?; + let data = self.transactions_to_view(data).await?; Ok(TransactionWithInfoPageView { data, @@ -666,8 +605,7 @@ impl RoochAPIServer for RoochServer { .aggregate_service .get_balance(account_addr.into(), coin_type.into()) .await - .map(Into::into) - .map_err(|e| err_obj(e.to_string()))?) + .map(Into::into)?) } /// get account balances by RoochAddress @@ -684,8 +622,7 @@ impl RoochAPIServer for RoochServer { let mut data = self .aggregate_service .get_balances(account_addr.into(), cursor, limit_of + 1) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); @@ -724,22 +661,17 @@ impl RoochAPIServer for RoochServer { let txs = self .rpc_service .query_transactions(filter.into(), cursor, limit_of + 1, descending_order) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let mut data = self .aggregate_service .build_transaction_with_infos(txs) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let has_next_page = data.len() > limit_of; data.truncate(limit_of); - let data = self - .transactions_to_view(data) - .await - .map_err(|e| err_obj(e.to_string()))?; + let data = self.transactions_to_view(data).await?; let next_cursor = data .last() @@ -771,8 +703,7 @@ impl RoochAPIServer for RoochServer { let mut data = self .rpc_service .query_events(filter.into(), cursor, limit_of + 1, descending_order) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(IndexerEventView::from) .collect::>(); @@ -807,13 +738,11 @@ impl RoochAPIServer for RoochServer { let descending_order = query_option.descending; let decode = query_option.decode; - let global_state_filter = ObjectStateFilterView::try_into_object_state_filter(filter) - .map_err(|e| err_obj(e.to_string()))?; + let global_state_filter = ObjectStateFilterView::try_into_object_state_filter(filter)?; let states = self .rpc_service .query_object_states(global_state_filter, cursor, limit_of + 1, descending_order) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; let object_ids = states .iter() @@ -823,8 +752,7 @@ impl RoochAPIServer for RoochServer { let annotated_states = self .rpc_service .get_annotated_states(access_path) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_iter() .map(|s| s.expect("object should exist!")) // TODO: is statedb always synced with indexer? .collect::>(); @@ -833,8 +761,7 @@ impl RoochAPIServer for RoochServer { let valid_states = annotated_states.iter().collect::>(); let valid_display_field_views = self .get_display_fields_and_render(valid_states, true) - .await - .map_err(|e| err_obj(e.to_string()))?; + .await?; annotated_states .into_iter() .zip(valid_display_field_views) @@ -860,21 +787,15 @@ impl RoochAPIServer for RoochServer { .collect::>() }; - let network = self - .rpc_service - .get_bitcoin_network() - .await - .map_err(|e| err_obj(e.to_string()))?; + let network = self.rpc_service.get_bitcoin_network().await?; let rooch_addresses = states.iter().map(|s| s.owner).collect::>(); let bitcoin_addresses = self .rpc_service .get_bitcoin_addresses(rooch_addresses) - .await - .map_err(|e| err_obj(e.to_string()))? + .await? .into_values() .map(|btc_addr| btc_addr.map(|addr| addr.format(network)).transpose()) - .collect::>>>() - .map_err(|e| err_obj(e.to_string()))?; + .collect::>>>()?; let mut data = annotated_states_with_display .into_iter() diff --git a/crates/rooch-rpc-server/src/service/mod.rs b/crates/rooch-rpc-server/src/service/mod.rs index 3c8acd0439..02eaf7e980 100644 --- a/crates/rooch-rpc-server/src/service/mod.rs +++ b/crates/rooch-rpc-server/src/service/mod.rs @@ -2,4 +2,5 @@ // SPDX-License-Identifier: Apache-2.0 pub mod aggregate_service; +pub mod rpc_logger; pub mod rpc_service; diff --git a/crates/rooch-rpc-server/src/service/rpc_logger.rs b/crates/rooch-rpc-server/src/service/rpc_logger.rs new file mode 100644 index 0000000000..330b1334d0 --- /dev/null +++ b/crates/rooch-rpc-server/src/service/rpc_logger.rs @@ -0,0 +1,31 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use jsonrpsee::server::middleware::rpc::RpcServiceT; +use jsonrpsee::types::Request; + +#[derive(Clone)] +pub struct RpcLogger(pub S); + +impl<'a, S> RpcServiceT<'a> for RpcLogger +where + S: RpcServiceT<'a> + Send + Sync, +{ + type Future = S::Future; + + fn call(&self, req: Request<'a>) -> Self::Future { + let params_str = match req.params().parse::() { + Ok(json) => json.to_string(), + Err(e) => e.to_string(), + }; + + tracing::event!( + tracing::Level::INFO, + event = "on_call", + method_name = req.method_name(), + params = params_str, + ); + + self.0.call(req) + } +} From f217a5dd2087ab1d546b6d2ec9926e751e2716f8 Mon Sep 17 00:00:00 2001 From: vegetabledogdog Date: Tue, 2 Jul 2024 15:21:22 +0800 Subject: [PATCH 4/4] [deps] update --- crates/rooch-rpc-client/src/client_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rooch-rpc-client/src/client_config.rs b/crates/rooch-rpc-client/src/client_config.rs index 1cf9314437..39b60a39ba 100644 --- a/crates/rooch-rpc-client/src/client_config.rs +++ b/crates/rooch-rpc-client/src/client_config.rs @@ -14,8 +14,8 @@ use std::fmt::{Display, Formatter, Write}; use std::path::PathBuf; pub const DEFAULT_EXPIRATION_SECS: u64 = 30; -pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network/"; -pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network/"; +pub const ROOCH_DEV_NET_URL: &str = "https://dev-seed.rooch.network"; +pub const ROOCH_TEST_NET_URL: &str = "https://test-seed.rooch.network"; #[derive(Serialize, Deserialize, Debug)] pub struct ClientConfig {