diff --git a/Cargo.lock b/Cargo.lock index 6ad425e680..2f732a4a6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -531,7 +531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df752953c49ce90719c7bf1fc587bc8227aed04732ea0c0f85e5397d7fdbd1a1" dependencies = [ "include_dir", - "itertools", + "itertools 0.10.3", "proc-macro-error", "proc-macro2", "quote", @@ -630,7 +630,7 @@ dependencies = [ "ark-std", "derivative", "hashbrown 0.13.2", - "itertools", + "itertools 0.10.3", "num-traits", "rayon", "zeroize", @@ -698,7 +698,7 @@ dependencies = [ "ark-std", "derivative", "digest 0.10.7", - "itertools", + "itertools 0.10.3", "num-bigint 0.4.3", "num-traits", "paste", @@ -1115,7 +1115,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -1254,7 +1254,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -1425,7 +1425,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -2151,7 +2151,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -2641,7 +2641,7 @@ dependencies = [ "cranelift-codegen 0.95.1", "cranelift-entity 0.95.1", "cranelift-frontend 0.95.1", - "itertools", + "itertools 0.10.3", "log", "smallvec", "wasmparser 0.102.0", @@ -2700,7 +2700,7 @@ dependencies = [ "clap 3.2.23", "criterion-plot", "futures", - "itertools", + "itertools 0.10.3", "lazy_static", "num-traits", "oorandom", @@ -2722,7 +2722,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", - "itertools", + "itertools 0.10.3", ] [[package]] @@ -2961,7 +2961,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -3076,7 +3076,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -3109,7 +3109,7 @@ checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ "darling_core 0.20.1", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -3240,7 +3240,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -3345,7 +3345,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics 0.10.0", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -3537,7 +3537,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.55", + "syn 2.0.59", "termcolor", "toml 0.8.2", "walkdir", @@ -3799,7 +3799,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -3839,7 +3839,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -4080,7 +4080,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.55", + "syn 2.0.59", "toml 0.7.3", "walkdir", ] @@ -4098,7 +4098,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -4124,7 +4124,7 @@ dependencies = [ "serde", "serde_json", "strum 0.25.0", - "syn 2.0.55", + "syn 2.0.59", "tempfile", "thiserror", "tiny-keccak", @@ -4284,7 +4284,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -4617,7 +4617,7 @@ dependencies = [ "frame-system", "gethostname", "handlebars", - "itertools", + "itertools 0.10.3", "lazy_static", "linked-hash-map", "log", @@ -4658,7 +4658,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -4792,13 +4792,13 @@ dependencies = [ "derive-syn-parse", "expander", "frame-support-procedural-tools", - "itertools", + "itertools 0.10.3", "macro_magic", "proc-macro-warning", "proc-macro2", "quote", "sp-core-hashing 9.0.0", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -4810,7 +4810,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -4820,7 +4820,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -5048,7 +5048,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -5495,6 +5495,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -6062,14 +6068,14 @@ dependencies = [ "impl-serde", "ink_ir", "ink_primitives", - "itertools", + "itertools 0.10.3", "log", "parity-scale-codec", "proc-macro2", "quote", "serde", "serde_json", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -6123,10 +6129,10 @@ checksum = "5b529c941518e8f450395fab9fe8ebba0a7acbb18778fc7e0a87f6248286ec72" dependencies = [ "blake2 0.10.6", "either", - "itertools", + "itertools 0.10.3", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -6141,7 +6147,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", "synstructure 0.13.0", ] @@ -6360,6 +6366,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -6678,7 +6693,7 @@ dependencies = [ "diff", "ena", "is-terminal", - "itertools", + "itertools 0.10.3", "lalrpop-util", "petgraph", "regex", @@ -7437,7 +7452,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -7451,7 +7466,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -7462,7 +7477,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -7473,7 +7488,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -7908,6 +7923,12 @@ name = "multimap" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + +[[package]] +name = "multimap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" dependencies = [ "serde", ] @@ -8310,7 +8331,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -8439,7 +8460,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -8718,7 +8739,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -9251,7 +9272,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -9810,7 +9831,7 @@ dependencies = [ "phala-node-runtime", "phala-trie-storage", "phala-types", - "prost 0.11.8", + "prost 0.12.4", "prpc", "prpc-build", "reqwest", @@ -10444,7 +10465,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -10483,7 +10504,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -10606,7 +10627,7 @@ dependencies = [ "proc-macro2", "quote", "rustfmt-snippet 0.1.0", - "syn 2.0.55", + "syn 2.0.59", "unzip3", ] @@ -10830,7 +10851,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -10840,7 +10861,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -10971,7 +10992,7 @@ checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" dependencies = [ "difflib", "float-cmp", - "itertools", + "itertools 0.10.3", "normalize-line-endings", "predicates-core", "regex", @@ -10985,7 +11006,7 @@ checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" dependencies = [ "anstyle", "difflib", - "itertools", + "itertools 0.10.3", "predicates-core", ] @@ -11034,7 +11055,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" dependencies = [ "proc-macro2", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -11117,14 +11138,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -11150,7 +11171,7 @@ checksum = "606c4ba35817e2922a308af55ad51bab3645b59eae5c570d4a6cf07e36bd493b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", "version_check", "yansi 0.5.1", ] @@ -11236,6 +11257,16 @@ dependencies = [ "prost-derive 0.11.8", ] +[[package]] +name = "prost" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" +dependencies = [ + "bytes", + "prost-derive 0.12.4", +] + [[package]] name = "prost-build" version = "0.9.0" @@ -11244,10 +11275,10 @@ checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", "heck 0.3.3", - "itertools", + "itertools 0.10.3", "lazy_static", "log", - "multimap", + "multimap 0.8.3", "petgraph", "prost 0.9.0", "prost-types 0.9.0", @@ -11264,10 +11295,10 @@ checksum = "2c828f93f5ca4826f97fedcbd3f9a536c16b12cff3dbbb4a007f932bbad95b12" dependencies = [ "bytes", "heck 0.4.1", - "itertools", + "itertools 0.10.3", "lazy_static", "log", - "multimap", + "multimap 0.8.3", "petgraph", "prettyplease 0.1.21", "prost 0.11.8", @@ -11278,6 +11309,27 @@ dependencies = [ "which", ] +[[package]] +name = "prost-build" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" +dependencies = [ + "bytes", + "heck 0.4.1", + "itertools 0.10.3", + "log", + "multimap 0.8.3", + "once_cell", + "petgraph", + "prettyplease 0.2.9", + "prost 0.12.4", + "prost-types 0.12.4", + "regex", + "syn 2.0.59", + "tempfile", +] + [[package]] name = "prost-derive" version = "0.9.0" @@ -11285,7 +11337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.3", "proc-macro2", "quote", "syn 1.0.109", @@ -11298,12 +11350,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.3", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "prost-derive" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +dependencies = [ + "anyhow", + "itertools 0.12.1", + "proc-macro2", + "quote", + "syn 2.0.59", +] + [[package]] name = "prost-types" version = "0.9.0" @@ -11323,34 +11388,61 @@ dependencies = [ "prost 0.11.8", ] +[[package]] +name = "prost-types" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" +dependencies = [ + "prost 0.12.4", +] + [[package]] name = "prpc" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2422a3de4c54a8700ebcb80be563e8dfc30a65c323ec9655f6a54736209cc173" dependencies = [ "anyhow", "async-trait", "derive_more", + "hex", + "hex_fmt", "parity-scale-codec", - "prost 0.11.8", + "prost 0.12.4", + "prpc-serde-bytes", + "serde", "serde_json", ] [[package]] name = "prpc-build" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d38aa9ef7bdf72bb2f4c3f4b790198beb68054e3213dcdbebfd323fb0141e8" dependencies = [ "either", - "heck 0.4.1", - "itertools", + "heck 0.5.0", + "itertools 0.12.1", "log", - "multimap", + "multimap 0.10.0", "proc-macro2", - "prost 0.11.8", - "prost-build 0.11.8", + "prost 0.12.4", + "prost-build 0.12.4", "prost-build 0.9.0", - "prost-types 0.11.8", + "prost-types 0.12.4", "quote", - "syn 1.0.109", + "syn 2.0.59", +] + +[[package]] +name = "prpc-serde-bytes" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac0855066edbf6bdcb42beb02cd9063d12d8d6d44b9a0c2f15a30e6ddd11f5" +dependencies = [ + "proc-macro2", + "syn 2.0.59", ] [[package]] @@ -12164,7 +12256,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn 2.0.55", + "syn 2.0.59", "unicode-xid", "version_check", ] @@ -12328,7 +12420,6 @@ name = "rustfmt-snippet" version = "0.1.1" dependencies = [ "proc-macro2", - "tempfile", ] [[package]] @@ -12687,7 +12778,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -12701,7 +12792,7 @@ dependencies = [ "clap 4.4.12", "fdlimit", "futures", - "itertools", + "itertools 0.10.3", "libp2p-identity", "log", "names", @@ -13597,7 +13688,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -14137,7 +14228,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -14638,7 +14729,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c792fe9fae2a2f716846f214ca10d5a1e21133e0bf36cef34bcc4a852467b21" dependencies = [ - "itertools", + "itertools 0.10.3", "lalrpop", "lalrpop-util", "phf 0.11.2", @@ -14678,7 +14769,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -14867,7 +14958,7 @@ dependencies = [ "hash-db", "hash256-std-hasher", "impl-serde", - "itertools", + "itertools 0.10.3", "libsecp256k1", "log", "merlin 2.0.1", @@ -14976,13 +15067,13 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "quote", "sp-core-hashing 9.0.0", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -15015,7 +15106,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -15026,17 +15117,17 @@ checksum = "50535e1a5708d3ba5c1195b59ebefac61cc8679c2c24716b87a86e8b7ed2e4a1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -15065,7 +15156,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "environmental", "parity-scale-codec", @@ -15284,7 +15375,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -15310,7 +15401,7 @@ dependencies = [ "proc-macro-crate 2.0.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -15323,20 +15414,20 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "Inflector", "expander", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -15427,7 +15518,7 @@ checksum = "54c78c5a66682568cc7b153603c5d01a2cc8f5c221c7b1e921517a0eef18ae05" [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" [[package]] name = "sp-storage" @@ -15459,7 +15550,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "impl-serde", "parity-scale-codec", @@ -15509,12 +15600,12 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ "parity-scale-codec", "tracing", "tracing-core", - "tracing-subscriber 0.2.25", + "tracing-subscriber 0.3.18", ] [[package]] @@ -15591,7 +15682,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -15624,13 +15715,11 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#cc1e6ac301ea88e3cb3253a84e4c6aa28f2d8f87" +source = "git+https://github.com/paritytech/polkadot-sdk#4e10d3b0a6ec2eccf58c471e7739948c1a867acf" dependencies = [ - "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", - "wasmtime", ] [[package]] @@ -15697,7 +15786,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" dependencies = [ - "itertools", + "itertools 0.10.3", "nom", "unicode_categories", ] @@ -16089,7 +16178,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -16355,7 +16444,7 @@ dependencies = [ "quote", "scale-info", "subxt-metadata", - "syn 2.0.55", + "syn 2.0.59", "thiserror", "tokio", ] @@ -16367,7 +16456,7 @@ dependencies = [ "darling 0.20.1", "proc-macro-error", "subxt-codegen", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -16414,9 +16503,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ "proc-macro2", "quote", @@ -16449,7 +16538,7 @@ checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", "unicode-xid", ] @@ -16630,7 +16719,7 @@ checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -16804,7 +16893,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -17085,7 +17174,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] @@ -17903,7 +17992,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", "wasm-bindgen-shared", ] @@ -17960,7 +18049,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -18132,7 +18221,7 @@ dependencies = [ "byteorder", "cc", "inkwell", - "itertools", + "itertools 0.10.3", "lazy_static", "libc", "object 0.28.4", @@ -19362,7 +19451,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.59", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a60de0d4ad..72837534e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,8 +53,6 @@ members = [ "crates/phala-node-rpc-ext", "crates/phala-types", "crates/phala-git-revision", - "crates/prpc", - "crates/prpc-build", "crates/phactory", "crates/phactory/api", "crates/phactory/pal", diff --git a/crates/phactory/Cargo.toml b/crates/phactory/Cargo.toml index 301515844d..03aa20a837 100644 --- a/crates/phactory/Cargo.toml +++ b/crates/phactory/Cargo.toml @@ -26,7 +26,7 @@ phala-mq = { path = "../phala-mq" } phala-serde-more = { path = "../phala-serde-more" } phala-crypto = { path = "../phala-crypto", features = ["getrandom", "stream"] } -prpc = { path = "../prpc" } +prpc = "0.1" pink-loader = { path = "../pink/loader" } pink-chain-extension = { path = "../pink/chain-extension" } pink = { path = "../pink/pink" } diff --git a/crates/phactory/api/Cargo.toml b/crates/phactory/api/Cargo.toml index 49b876597a..020cf15278 100644 --- a/crates/phactory/api/Cargo.toml +++ b/crates/phactory/api/Cargo.toml @@ -10,11 +10,11 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive serde = { version = "1", features = ["derive"], default-features = false } base64 = { version = "0.13" } derive_more = { version = "0.99.17" } -prost = "0.11.8" +prost = "0.12.4" phala-trie-storage = { path = "../../../crates/phala-trie-storage", default-features = false, features = ["serde"] } phala-types = { path = "../../../crates/phala-types", default-features = false, features = ["enable_serde", "sgx"] } -prpc = { path = "../../../crates/prpc", default-features = false } +prpc = { version = "0.1", default-features = false } phala-crypto = { path = "../../../crates/phala-crypto" } chain = { path = "../../../standalone/runtime", default-features = false, package = "phala-node-runtime" } @@ -42,7 +42,7 @@ hex = "0.4.3" type-info-stringify = { path = "../../type-info-stringify" } [build-dependencies] -prpc-build = { path = "../../../crates/prpc-build" } +prpc-build = "0.1" tera = { version = "1.12.1" } tempdir = { version = "0.3.7" } diff --git a/crates/phactory/api/src/crypto.rs b/crates/phactory/api/src/crypto.rs index 5518e6c678..d61bc271e3 100644 --- a/crates/phactory/api/src/crypto.rs +++ b/crates/phactory/api/src/crypto.rs @@ -78,9 +78,9 @@ impl Signature { if max_depth == 0 { return Err(SignatureVerifyError::TooLongCertificateChain); } - let sig_type = match SignatureType::from_i32(self.signature_type) { - Some(val) => val, - None => { + let sig_type = match SignatureType::try_from(self.signature_type) { + Ok(val) => val, + Err(_) => { return Err(SignatureVerifyError::InvalidSignatureType); } }; diff --git a/crates/phala-types/Cargo.toml b/crates/phala-types/Cargo.toml index bc557de644..8a5897740c 100644 --- a/crates/phala-types/Cargo.toml +++ b/crates/phala-types/Cargo.toml @@ -12,7 +12,7 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0", default-features = false } phala-mq = { path = "../../crates/phala-mq", default-features = false } -prpc = { path = "../../crates/prpc", default-features = false } +prpc = { version = "0.1", default-features = false } pink-types = { path = "../pink/pink-types", default-features = false } sgx-attestation = { path = "../sgx-attestation", default-features = false, optional = true } diff --git a/crates/prpc-build/Cargo.toml b/crates/prpc-build/Cargo.toml deleted file mode 100644 index 242ca9c2aa..0000000000 --- a/crates/prpc-build/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "prpc-build" -version = "0.1.0" -edition = "2018" - -[dependencies] -protoc = { version = "0.9", package = "prost-build" } -prost-build = { version = "0.11.8" } -syn = "1.0.98" -quote = "1.0" -proc-macro2 = "1.0" -prost-types = "0.11.8" -prost = "0.11.8" -itertools = "0.10.1" -either = "1.6.1" -multimap = "0.8.3" -heck = "0.4.0" -log = "0.4.14" diff --git a/crates/prpc-build/src/client.rs b/crates/prpc-build/src/client.rs deleted file mode 100644 index cd865385e4..0000000000 --- a/crates/prpc-build/src/client.rs +++ /dev/null @@ -1,107 +0,0 @@ -use super::{Attributes, Method, Service}; -use crate::{generate_doc_comments, naive_snake_case}; -use proc_macro2::TokenStream; -use quote::{format_ident, quote}; - -/// Generate service for client. -/// -/// This takes some `Service` and will generate a `TokenStream` that contains -/// a public module with the generated client. -pub fn generate( - service: &T, - emit_package: bool, - proto_path: &str, - compile_well_known_types: bool, - attributes: &Attributes, -) -> TokenStream { - let service_ident = quote::format_ident!("{}Client", service.name()); - let client_mod = quote::format_ident!("{}_client", naive_snake_case(service.name())); - let methods = generate_methods(service, emit_package, proto_path, compile_well_known_types); - - let service_doc = generate_doc_comments(service.comment()); - - let package = if emit_package { service.package() } else { "" }; - let path = format!( - "{}{}{}", - package, - if package.is_empty() { "" } else { "." }, - service.identifier() - ); - - let mod_attributes = attributes.for_mod(package); - let struct_attributes = attributes.for_struct(&path); - - quote! { - /// Generated client implementations. - #(#mod_attributes)* - pub mod #client_mod { - #service_doc - #(#struct_attributes)* - #[derive(Debug)] - pub struct #service_ident { - pub client: Client, - } - - impl #service_ident - where - Client: prpc::client::RequestClient - { - pub fn new(client: Client) -> Self { - Self { client } - } - - #methods - } - } - } -} - -fn generate_methods( - service: &T, - emit_package: bool, - proto_path: &str, - compile_well_known_types: bool, -) -> TokenStream { - let mut stream = TokenStream::new(); - for method in service.methods() { - let path = crate::join_path( - emit_package, - service.package(), - service.identifier(), - method.identifier(), - ); - - stream.extend(generate_doc_comments(method.comment())); - - let method = match (method.client_streaming(), method.server_streaming()) { - (false, false) => generate_unary(method, proto_path, compile_well_known_types, path), - _ => { - panic!("Only unary method supported"); - } - }; - - stream.extend(method); - } - - stream -} - -fn generate_unary( - method: &T, - proto_path: &str, - compile_well_known_types: bool, - path: String, -) -> TokenStream { - let ident = format_ident!("{}", method.name()); - let (request, response) = method.request_response_name(proto_path, compile_well_known_types); - - quote! { - pub async fn #ident( - &self, - request: #request, - ) -> Result<#response, prpc::client::Error> { - let response = self.client.request(#path, prpc::codec::encode_message_to_vec(&request)).await?; - Ok(prpc::Message::decode(&response[..])?) - } - } -} diff --git a/crates/prpc-build/src/lib.rs b/crates/prpc-build/src/lib.rs deleted file mode 100644 index ea825e0b1b..0000000000 --- a/crates/prpc-build/src/lib.rs +++ /dev/null @@ -1,292 +0,0 @@ -#![recursion_limit = "256"] - -use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream}; -use quote::TokenStreamExt; -mod prost; - -pub use crate::prost::{compile_protos, configure, Builder}; - -use std::io::{self, Write}; -use std::process::Command; - -/// Service code generation for client -pub mod client; -/// Service code generation for Server -pub mod server; - -mod protos_codec_extension; - -/// Service generation trait. -/// -/// This trait can be implemented and consumed -/// by `client::generate` and `server::generate` -/// to allow any codegen module to generate service -/// abstractions. -pub trait Service { - /// Comment type. - type Comment: AsRef; - - /// Method type. - type Method: Method; - - /// Name of service. - fn name(&self) -> &str; - /// Package name of service. - fn package(&self) -> &str; - /// Identifier used to generate type name. - fn identifier(&self) -> &str; - /// Methods provided by service. - fn methods(&self) -> &[Self::Method]; - /// Get comments about this item. - fn comment(&self) -> &[Self::Comment]; -} - -/// Method generation trait. -/// -/// Each service contains a set of generic -/// `Methods`'s that will be used by codegen -/// to generate abstraction implementations for -/// the provided methods. -pub trait Method { - /// Comment type. - type Comment: AsRef; - - /// Name of method. - fn name(&self) -> &str; - /// Identifier used to generate type name. - fn identifier(&self) -> &str; - /// Method is streamed by client. - fn client_streaming(&self) -> bool; - /// Method is streamed by server. - fn server_streaming(&self) -> bool; - /// Get comments about this item. - fn comment(&self) -> &[Self::Comment]; - /// Type name of request and response. - fn request_response_name( - &self, - proto_path: &str, - compile_well_known_types: bool, - ) -> (TokenStream, TokenStream); -} - -/// Attributes that will be added to `mod` and `struct` items. -#[derive(Debug, Default, Clone)] -pub struct Attributes { - /// `mod` attributes. - module: Vec<(String, String)>, - /// `struct` attributes. - structure: Vec<(String, String)>, -} - -impl Attributes { - fn for_mod(&self, name: &str) -> Vec { - generate_attributes(name, &self.module) - } - - fn for_struct(&self, name: &str) -> Vec { - generate_attributes(name, &self.structure) - } - - /// Add an attribute that will be added to `mod` items matching the given pattern. - /// - /// # Examples - /// - /// ``` - /// # use prpc_build::*; - /// let mut attributes = Attributes::default(); - /// attributes.push_mod("my.proto.package", r#"#[cfg(feature = "server")]"#); - /// ``` - pub fn push_mod(&mut self, pattern: impl Into, attr: impl Into) { - self.module.push((pattern.into(), attr.into())); - } - - /// Add an attribute that will be added to `struct` items matching the given pattern. - /// - /// # Examples - /// - /// ``` - /// # use prpc_build::*; - /// let mut attributes = Attributes::default(); - /// attributes.push_struct("EchoService", "#[derive(PartialEq)]"); - /// ``` - pub fn push_struct(&mut self, pattern: impl Into, attr: impl Into) { - self.structure.push((pattern.into(), attr.into())); - } -} - -// Generates attributes given a list of (`pattern`, `attribute`) pairs. If `pattern` matches `name`, `attribute` will be included. -fn generate_attributes<'a>( - name: &str, - attrs: impl IntoIterator, -) -> Vec { - attrs - .into_iter() - .filter(|(matcher, _)| match_name(matcher, name)) - .flat_map(|(_, attr)| { - // attributes cannot be parsed directly, so we pretend they're on a struct - syn::parse_str::(&format!("{attr}\nstruct fake;")) - .unwrap() - .attrs - }) - .collect::>() -} - -/// Format files under the out_dir with rustfmt -pub fn fmt(out_dir: &str) { - let dir = std::fs::read_dir(out_dir).unwrap(); - - for entry in dir { - let file = entry.unwrap().file_name().into_string().unwrap(); - if !file.ends_with(".rs") { - continue; - } - let result = - Command::new(std::env::var("RUSTFMT").unwrap_or_else(|_| "rustfmt".to_owned())) - .arg("--emit") - .arg("files") - .arg("--edition") - .arg("2018") - .arg(format!("{out_dir}/{file}")) - .output(); - - match result { - Err(e) => { - eprintln!("error running rustfmt: {e:?}"); - // exit(1) - } - Ok(output) => { - if !output.status.success() { - io::stdout().write_all(&output.stdout).unwrap(); - io::stderr().write_all(&output.stderr).unwrap(); - //exit(output.status.code().unwrap_or(1)) - } - } - } - } -} - -// Generate a singular line of a doc comment -fn generate_doc_comment>(comment: S) -> TokenStream { - let mut doc_stream = TokenStream::new(); - - doc_stream.append(Ident::new("doc", Span::call_site())); - doc_stream.append(Punct::new('=', Spacing::Alone)); - doc_stream.append(Literal::string(comment.as_ref())); - - let group = Group::new(Delimiter::Bracket, doc_stream); - - let mut stream = TokenStream::new(); - stream.append(Punct::new('#', Spacing::Alone)); - stream.append(group); - stream -} - -// Generate a larger doc comment composed of many lines of doc comments -fn generate_doc_comments>(comments: &[T]) -> TokenStream { - let mut stream = TokenStream::new(); - - for comment in comments { - stream.extend(generate_doc_comment(comment)); - } - - stream -} - -// Checks whether a path pattern matches a given path. -pub(crate) fn match_name(pattern: &str, path: &str) -> bool { - if pattern.is_empty() { - false - } else if pattern == "." || pattern == path { - true - } else { - let pattern_segments = pattern.split('.').collect::>(); - let path_segments = path.split('.').collect::>(); - - if &pattern[..1] == "." { - // prefix match - if pattern_segments.len() > path_segments.len() { - false - } else { - pattern_segments[..] == path_segments[..pattern_segments.len()] - } - // suffix match - } else if pattern_segments.len() > path_segments.len() { - false - } else { - pattern_segments[..] == path_segments[path_segments.len() - pattern_segments.len()..] - } - } -} - -fn naive_snake_case(name: &str) -> String { - let mut s = String::new(); - let mut it = name.chars().peekable(); - - while let Some(x) = it.next() { - s.push(x.to_ascii_lowercase()); - if let Some(y) = it.peek() { - if y.is_uppercase() { - s.push('_'); - } - } - } - - s -} - -fn join_path(emit_package: bool, package: &str, service: &str, method: &str) -> String { - let mut path = String::new(); - if emit_package { - path += package; - } - - if !path.is_empty() { - path += "."; - } - - path += service; - - if !method.is_empty() { - path += "."; - path += method; - } - path -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_match_name() { - assert!(match_name(".", ".my.protos")); - assert!(match_name(".", ".protos")); - - assert!(match_name(".my", ".my")); - assert!(match_name(".my", ".my.protos")); - assert!(match_name(".my.protos.Service", ".my.protos.Service")); - - assert!(match_name("Service", ".my.protos.Service")); - - assert!(!match_name(".m", ".my.protos")); - assert!(!match_name(".p", ".protos")); - - assert!(!match_name(".my", ".myy")); - assert!(!match_name(".protos", ".my.protos")); - assert!(!match_name(".Service", ".my.protos.Service")); - - assert!(!match_name("service", ".my.protos.Service")); - } - - #[test] - fn test_snake_case() { - for case in &[ - ("Service", "service"), - ("ThatHasALongName", "that_has_a_long_name"), - ("greeter", "greeter"), - ("ABCServiceX", "a_b_c_service_x"), - ] { - assert_eq!(naive_snake_case(case.0), case.1) - } - } -} diff --git a/crates/prpc-build/src/prost.rs b/crates/prpc-build/src/prost.rs deleted file mode 100644 index 8d7c8b0fc7..0000000000 --- a/crates/prpc-build/src/prost.rs +++ /dev/null @@ -1,447 +0,0 @@ -use super::{client, server, Attributes}; -use proc_macro2::TokenStream; -use prost_build::{Config, Method, Service}; -use quote::ToTokens; -use std::ffi::OsString; -use std::io; -use std::path::{Path, PathBuf}; - -/// Configure `prpc-build` code generation. -/// -/// Use [`compile_protos`] instead if you don't need to tweak anything. -pub fn configure() -> Builder { - Builder { - build_client: true, - build_server: true, - out_dir: None, - extern_path: Vec::new(), - field_attributes: Vec::new(), - type_attributes: Vec::new(), - server_attributes: Attributes::default(), - client_attributes: Attributes::default(), - proto_path: "super".to_string(), - compile_well_known_types: false, - format: true, - emit_package: true, - protoc_args: Vec::new(), - file_descriptor_set_path: None, - mod_prefix: Default::default(), - type_prefix: Default::default(), - } -} - -/// Simple `.proto` compiling. Use [`configure`] instead if you need more options. -/// -/// The include directory will be the parent folder of the specified path. -/// The package name will be the filename without the extension. -pub fn compile_protos(proto: impl AsRef) -> io::Result<()> { - let proto_path: &Path = proto.as_ref(); - - // directory the main .proto file resides in - let proto_dir = proto_path - .parent() - .expect("proto file should reside in a directory"); - - self::configure().compile(&[proto_path], &[proto_dir])?; - - Ok(()) -} - -impl crate::Service for Service { - type Method = Method; - type Comment = String; - - fn name(&self) -> &str { - &self.name - } - - fn package(&self) -> &str { - &self.package - } - - fn identifier(&self) -> &str { - &self.proto_name - } - - fn comment(&self) -> &[Self::Comment] { - &self.comments.leading[..] - } - - fn methods(&self) -> &[Self::Method] { - &self.methods[..] - } -} - -impl crate::Method for Method { - type Comment = String; - - fn name(&self) -> &str { - &self.name - } - - fn identifier(&self) -> &str { - &self.proto_name - } - - fn client_streaming(&self) -> bool { - self.client_streaming - } - - fn server_streaming(&self) -> bool { - self.server_streaming - } - - fn comment(&self) -> &[Self::Comment] { - &self.comments.leading[..] - } - - fn request_response_name( - &self, - proto_path: &str, - compile_well_known_types: bool, - ) -> (TokenStream, TokenStream) { - let request = if (is_google_type(&self.input_proto_type) && !compile_well_known_types) - || self.input_type.starts_with("::") - { - self.input_type.parse::().unwrap() - } else if self.input_type.starts_with("crate::") { - syn::parse_str::(&self.input_type) - .unwrap() - .to_token_stream() - } else { - syn::parse_str::(&format!("{proto_path}::{}", self.input_type)) - .unwrap() - .to_token_stream() - }; - - let response = if (is_google_type(&self.output_proto_type) && !compile_well_known_types) - || self.output_type.starts_with("::") - { - self.output_type.parse::().unwrap() - } else if self.output_type.starts_with("crate::") { - syn::parse_str::(&self.output_type) - .unwrap() - .to_token_stream() - } else { - syn::parse_str::(&format!("{proto_path}::{}", self.output_type)) - .unwrap() - .to_token_stream() - }; - - (request, response) - } -} - -fn is_google_type(ty: &str) -> bool { - ty.starts_with(".google.protobuf") -} - -struct ServiceGenerator { - builder: Builder, - clients: TokenStream, - servers: TokenStream, -} - -impl ServiceGenerator { - fn new(builder: Builder) -> Self { - ServiceGenerator { - builder, - clients: TokenStream::default(), - servers: TokenStream::default(), - } - } -} - -impl prost_build::ServiceGenerator for ServiceGenerator { - fn generate(&mut self, service: prost_build::Service, _buf: &mut String) { - if self.builder.build_server { - let server = server::generate( - &service, - self.builder.emit_package, - &self.builder.proto_path, - self.builder.compile_well_known_types, - &self.builder.server_attributes, - ); - self.servers.extend(server); - } - - if self.builder.build_client { - let client = client::generate( - &service, - self.builder.emit_package, - &self.builder.proto_path, - self.builder.compile_well_known_types, - &self.builder.client_attributes, - ); - self.clients.extend(client); - } - } - - fn finalize(&mut self, buf: &mut String) { - if self.builder.build_client && !self.clients.is_empty() { - let code = format!("{}", self.clients); - buf.push_str(&code); - - self.clients = TokenStream::default(); - } - - if self.builder.build_server && !self.servers.is_empty() { - let code = format!("{}", self.servers); - buf.push_str(&code); - - self.servers = TokenStream::default(); - } - } -} - -/// Service generator builder. -#[derive(Debug, Clone)] -pub struct Builder { - pub(crate) build_client: bool, - pub(crate) build_server: bool, - pub(crate) extern_path: Vec<(String, String)>, - pub(crate) field_attributes: Vec<(String, String)>, - pub(crate) type_attributes: Vec<(String, String)>, - pub(crate) server_attributes: Attributes, - pub(crate) client_attributes: Attributes, - pub(crate) proto_path: String, - pub(crate) emit_package: bool, - pub(crate) compile_well_known_types: bool, - pub(crate) protoc_args: Vec, - - mod_prefix: String, - type_prefix: String, - file_descriptor_set_path: Option, - out_dir: Option, - format: bool, -} - -impl Builder { - /// Enable or disable client code generation. - pub fn build_client(mut self, enable: bool) -> Self { - self.build_client = enable; - self - } - - /// Enable or disable server code generation. - pub fn build_server(mut self, enable: bool) -> Self { - self.build_server = enable; - self - } - - /// Enable the output to be formated by rustfmt. - pub fn format(mut self, run: bool) -> Self { - self.format = run; - self - } - - /// Module prefix of the generated code. - pub fn mod_prefix(mut self, prefix: impl Into) -> Self { - self.mod_prefix = prefix.into(); - self - } - - /// Type prefix of the scale codec anotation in the proto file. - pub fn type_prefix(mut self, prefix: impl Into) -> Self { - self.type_prefix = prefix.into(); - self - } - - /// Set the output directory to generate code to. - /// - /// Defaults to the `OUT_DIR` environment variable. - pub fn out_dir(mut self, out_dir: impl AsRef) -> Self { - self.out_dir = Some(out_dir.as_ref().to_path_buf()); - self - } - - /// Declare externally provided Protobuf package or type. - /// - /// Passed directly to `prost_build::Config.extern_path`. - /// Note that both the Protobuf path and the rust package paths should both be fully qualified. - /// i.e. Protobuf paths should start with "." and rust paths should start with "::" - pub fn extern_path(mut self, proto_path: impl AsRef, rust_path: impl AsRef) -> Self { - self.extern_path.push(( - proto_path.as_ref().to_string(), - rust_path.as_ref().to_string(), - )); - self - } - - /// Add additional attribute to matched messages, enums, and one-offs. - /// - /// Passed directly to `prost_build::Config.field_attribute`. - pub fn field_attribute, A: AsRef>(mut self, path: P, attribute: A) -> Self { - self.field_attributes - .push((path.as_ref().to_string(), attribute.as_ref().to_string())); - self - } - - /// Add additional attribute to matched messages, enums, and one-offs. - /// - /// Passed directly to `prost_build::Config.type_attribute`. - pub fn type_attribute, A: AsRef>(mut self, path: P, attribute: A) -> Self { - self.type_attributes - .push((path.as_ref().to_string(), attribute.as_ref().to_string())); - self - } - - /// Add additional attribute to matched server `mod`s. Matches on the package name. - pub fn server_mod_attribute, A: AsRef>( - mut self, - path: P, - attribute: A, - ) -> Self { - self.server_attributes - .push_mod(path.as_ref().to_string(), attribute.as_ref().to_string()); - self - } - - /// Add additional attribute to matched service servers. Matches on the service name. - pub fn server_attribute, A: AsRef>(mut self, path: P, attribute: A) -> Self { - self.server_attributes - .push_struct(path.as_ref().to_string(), attribute.as_ref().to_string()); - self - } - - /// Add additional attribute to matched client `mod`s. Matches on the package name. - pub fn client_mod_attribute, A: AsRef>( - mut self, - path: P, - attribute: A, - ) -> Self { - self.client_attributes - .push_mod(path.as_ref().to_string(), attribute.as_ref().to_string()); - self - } - - /// Add additional attribute to matched service clients. Matches on the service name. - pub fn client_attribute, A: AsRef>(mut self, path: P, attribute: A) -> Self { - self.client_attributes - .push_struct(path.as_ref().to_string(), attribute.as_ref().to_string()); - self - } - - /// Set the path to where to search for the Request/Response proto structs - /// live relative to the module where you call `include_proto!`. - /// - /// This defaults to `super` since we will generate code in a module. - pub fn proto_path(mut self, proto_path: impl AsRef) -> Self { - self.proto_path = proto_path.as_ref().to_string(); - self - } - - /// Configure Prost `protoc_args` build arguments. - /// - /// Note: Enabling `--experimental_allow_proto3_optional` requires protobuf >= 3.12. - pub fn protoc_arg>(mut self, arg: A) -> Self { - self.protoc_args.push(arg.as_ref().into()); - self - } - - /// Emits RPC endpoints with no attached package. Effectively ignores protofile package declaration from rpc context. - /// - /// This effectively sets prost's exported package to an empty string. - pub fn disable_package_emission(mut self) -> Self { - self.emit_package = false; - self - } - - /// Enable or disable directing Prost to compile well-known protobuf types instead - /// of using the already-compiled versions available in the `prost-types` crate. - /// - /// This defaults to `false`. - pub fn compile_well_known_types(mut self, compile_well_known_types: bool) -> Self { - self.compile_well_known_types = compile_well_known_types; - self - } - - /// When set, the `FileDescriptorSet` generated by `protoc` is written to the provided - /// filesystem path. - /// - /// This option can be used in conjunction with the [`include_bytes!`] macro and the types in - /// the `prost-types` crate for implementing reflection capabilities, among other things. - pub fn file_descriptor_set_path(mut self, path: impl Into) -> Self { - self.file_descriptor_set_path = Some(path.into()); - self - } - - /// Compile the .proto files and execute code generation. - pub fn compile( - self, - protos: &[impl AsRef], - includes: &[impl AsRef], - ) -> io::Result<()> { - self.compile_with_config(Config::new(), protos, includes) - } - - /// Compile the .proto files and execute code generation using a - /// custom `prost_build::Config`. - pub fn compile_with_config( - self, - mut config: Config, - protos: &[impl AsRef], - includes: &[impl AsRef], - ) -> io::Result<()> { - let out_dir = if let Some(out_dir) = self.out_dir.as_ref() { - out_dir.clone() - } else { - PathBuf::from(std::env::var("OUT_DIR").unwrap()) - }; - - let format = self.format; - - config.out_dir(out_dir.clone()); - for (proto_path, rust_path) in self.extern_path.iter() { - config.extern_path(proto_path, rust_path); - } - for (prost_path, attr) in self.field_attributes.iter() { - config.field_attribute(prost_path, attr); - } - for (prost_path, attr) in self.type_attributes.iter() { - config.type_attribute(prost_path, attr); - } - if self.compile_well_known_types { - config.compile_well_known_types(); - } - - for arg in self.protoc_args.iter() { - config.protoc_arg(arg); - } - - let file_descriptor_set_path = - if let Some(file_descriptor_set_path) = &self.file_descriptor_set_path { - file_descriptor_set_path.clone() - } else { - out_dir.join("file_descriptor_set.bin") - }; - config.file_descriptor_set_path(file_descriptor_set_path.clone()); - - let mod_prefix = self.mod_prefix.clone(); - let type_prefix = self.type_prefix.clone(); - - config.service_generator(Box::new(ServiceGenerator::new(self))); - - if std::env::var("PROTOC").is_err() { - std::env::set_var("PROTOC", protoc::protoc()); - } - config.compile_protos(protos, includes)?; - - let patch_file = out_dir.join("protos_codec_extensions.rs"); - - crate::protos_codec_extension::extend_types( - &file_descriptor_set_path, - patch_file, - &mod_prefix, - &type_prefix, - ); - - { - if format { - super::fmt(out_dir.to_str().expect("Expected utf8 out_dir")); - } - } - - Ok(()) - } -} diff --git a/crates/prpc-build/src/protos_codec_extension.rs b/crates/prpc-build/src/protos_codec_extension.rs deleted file mode 100644 index 2ebe3765f0..0000000000 --- a/crates/prpc-build/src/protos_codec_extension.rs +++ /dev/null @@ -1,453 +0,0 @@ -use either::Either; -use heck::{ToSnakeCase, ToUpperCamelCase}; -use itertools::Itertools; -use log::debug; -use multimap::MultiMap; -use prost_types::field_descriptor_proto::{Label, Type}; -use prost_types::source_code_info::Location; -use prost_types::{ - DescriptorProto, FieldDescriptorProto, FileDescriptorProto, FileDescriptorSet, SourceCodeInfo, -}; -use std::collections::HashMap; - -#[derive(PartialEq)] -enum Syntax { - Proto2, - Proto3, -} - -pub struct CodeGenerator<'a> { - package: String, - source_info: SourceCodeInfo, - syntax: Syntax, - depth: u8, - path: Vec, - buf: &'a mut String, - mod_path: Vec, - mod_prefix: String, - type_prefix: String, -} - -impl<'a> CodeGenerator<'a> { - pub fn generate( - file: FileDescriptorProto, - buf: &mut String, - mod_prefix: impl Into, - type_prefix: impl Into, - ) { - let mut source_info = file - .source_code_info - .expect("no source code info in request"); - source_info.location.retain(|location| { - let len = location.path.len(); - len > 0 && len % 2 == 0 - }); - source_info - .location - .sort_by_key(|location| location.path.clone()); - - let syntax = match file.syntax.as_deref() { - None | Some("proto2") => Syntax::Proto2, - Some("proto3") => Syntax::Proto3, - Some(s) => panic!("unknown syntax: {}", s), - }; - - let mut code_gen = CodeGenerator { - package: file.package.unwrap(), - source_info, - syntax, - depth: 0, - path: Vec::new(), - buf, - mod_path: vec![], - mod_prefix: mod_prefix.into(), - type_prefix: type_prefix.into(), - }; - - debug!( - "file: {:?}, package: {:?}", - file.name.as_ref().unwrap(), - code_gen.package - ); - - code_gen.path.push(4); - for (idx, message) in file.message_type.into_iter().enumerate() { - code_gen.path.push(idx as i32); - code_gen.append_message(message); - code_gen.path.pop(); - } - code_gen.path.pop(); - } - - fn append_message(&mut self, message: DescriptorProto) { - debug!(" message: {:?}", message.name()); - - let mut impl_buf = String::new(); - if self.append_message_impl(message.clone(), &mut impl_buf) { - self.buf.push_str(&impl_buf); - } - - let message_name = message.name().to_string(); - let fq_message_name = format!(".{}.{}", self.package, message.name()); - - // Split the nested message types into a vector of normal nested message types, and a map - // of the map field entry types. The path index of the nested message types is preserved so - // that comments can be retrieved. - type NestedTypes = Vec<(DescriptorProto, usize)>; - type MapTypes = HashMap; - let (nested_types, _): (NestedTypes, MapTypes) = message - .nested_type - .into_iter() - .enumerate() - .partition_map(|(idx, nested_type)| { - if nested_type - .options - .as_ref() - .and_then(|options| options.map_entry) - .unwrap_or(false) - { - let key = nested_type.field[0].clone(); - let value = nested_type.field[1].clone(); - assert_eq!("key", key.name()); - assert_eq!("value", value.name()); - - let name = format!("{}.{}", &fq_message_name, nested_type.name()); - Either::Right((name, (key, value))) - } else { - Either::Left((nested_type, idx)) - } - }); - if !nested_types.is_empty() { - self.push_mod(&message_name); - self.path.push(3); - for (nested_type, idx) in nested_types { - self.path.push(idx as i32); - self.append_message(nested_type); - self.path.pop(); - } - self.path.pop(); - self.pop_mod(); - } - } - - fn append_field(&mut self, field: FieldDescriptorProto, buf: &mut String) -> bool { - let optional = self.optional(&field); - let ty = self.resolve_decoded_type(&field); - - debug!(" field: {:?}, type: {:?}", field.name(), ty,); - - if let Some((name, _type_path)) = self.codec_decoration() { - match name.as_str() { - "scale" => { - buf.push_str(&format!( - "pub fn decode_{}(&self) -> Result<{}, ScaleDecodeError> {{\n", - self.typed_field_name(&field), - ty - )); - if optional { - buf.push_str(&format!( - "self.{}.as_ref().map(|v| Decode::decode(&mut &v[..])).transpose()", - field.name() - )); - } else { - buf.push_str(&format!("Decode::decode(&mut &self.{}[..])", field.name())); - } - buf.push_str("\n}\n"); - return true; - } - _ => { - panic!("Unknown codec {}", name); - } - } - } - false - } - - fn append_message_impl(&mut self, message: DescriptorProto, buf: &mut String) -> bool { - let message_name = message.name().to_string(); - // Split the fields into a vector of the normal fields, and oneof fields. - // Path indexes are preserved so that comments can be retrieved. - type Fields = Vec<(FieldDescriptorProto, usize)>; - type OneofFields = MultiMap; - let (fields, _): (Fields, OneofFields) = message - .field - .into_iter() - .enumerate() - .partition_map(|(idx, field)| { - if field.proto3_optional.unwrap_or(false) { - Either::Left((field, idx)) - } else if let Some(oneof_index) = field.oneof_index { - Either::Right((oneof_index, (field, idx))) - } else { - Either::Left((field, idx)) - } - }); - - buf.push_str("impl "); - let mut msg_path = self.mod_path.clone(); - msg_path.push(to_upper_camel(&message_name)); - let msg_path = self.mod_prefix.clone() + &msg_path.join("::"); - buf.push_str(&msg_path); - buf.push_str(" {\n"); - - self.path.push(2); - let mut n_fields = 0; - for (field, idx) in fields.clone() { - self.path.push(idx as i32); - if self.append_field(field, buf) { - n_fields += 1; - } - self.path.pop(); - } - self.path.pop(); - - if n_fields > 0 { - buf.push_str("pub fn new(\n"); - self.path.push(2); - for (field, idx) in fields.clone() { - self.path.push(idx as i32); - buf.push_str(&format!( - "{}: {},\n", - self.typed_field_name(&field), - self.resolve_decoded_type(&field) - )); - self.path.pop(); - } - self.path.pop(); - buf.push_str(") -> Self {\n"); - buf.push_str(" Self{\n"); - self.path.push(2); - for (field, idx) in fields { - self.path.push(idx as i32); - if self.codec_decoration().is_some() { - if self.optional(&field) { - buf.push_str(&format!( - "{}: {}.map(|x| x.encode()),\n", - field.name(), - self.typed_field_name(&field), - )); - } else { - buf.push_str(&format!( - "{}: {}.encode(),\n", - field.name(), - self.typed_field_name(&field) - )); - } - } else { - buf.push_str(&format!("{},\n", field.name())); - } - self.path.pop(); - } - self.path.pop(); - buf.push_str(" }\n"); - buf.push_str("}\n"); - } - - buf.push_str("\n}\n"); - n_fields > 0 - } - - fn location(&self) -> &Location { - let idx = self - .source_info - .location - .binary_search_by_key(&&self.path[..], |location| &location.path[..]) - .unwrap(); - - &self.source_info.location[idx] - } - - fn find_comment(&self, predicate: impl Fn(&str) -> Option) -> Option { - let comments = self.location().leading_comments(); - comments - .split('\n') - .find_map(|line| predicate(line.trim_start())) - } - - fn codec_decoration(&self) -> Option<(String, String)> { - self.find_comment(|line| { - let parts: Vec<_> = line.split_whitespace().collect(); - match parts[..] { - ["@codec", name, type_path] => Some((name.to_owned(), type_path.to_owned())), - _ => None, - } - }) - } - - fn boxed_decoration(&self) -> bool { - self.find_comment(|line| { - if line.starts_with("@boxed") { - Some(()) - } else { - None - } - }) - .is_some() - } - - fn push_mod(&mut self, module: &str) { - self.mod_path.push(to_snake(module)); - self.depth += 1; - } - - fn pop_mod(&mut self) { - self.depth -= 1; - self.mod_path.pop(); - } - - fn optional(&self, field: &FieldDescriptorProto) -> bool { - if field.proto3_optional.unwrap_or(false) { - return true; - } - - if field.label() != Label::Optional { - return false; - } - - match field.r#type() { - Type::Message => true, - _ => self.syntax == Syntax::Proto2, - } - } - - fn typed_field_name<'f>(&self, field: &'f FieldDescriptorProto) -> &'f str { - let encode_prefix = "encoded_"; - let field_name = field.name(); - if self.codec_decoration().is_some() - && field_name.starts_with(encode_prefix) - && field_name.len() > encode_prefix.len() - { - &field_name[encode_prefix.len()..] - } else { - field_name - } - } - - fn resolve_decoded_type(&self, field: &FieldDescriptorProto) -> String { - if let Some((_name, type_path)) = self.codec_decoration() { - let type_path = self.type_prefix.clone() + type_path.as_str(); - if self.optional(field) { - return format!("Option<{type_path}>"); - } else { - return type_path; - } - } - self.resolve_type(field) - } - - fn resolve_type(&self, field: &FieldDescriptorProto) -> String { - let ty = match field.r#type() { - Type::Float => String::from("f32"), - Type::Double => String::from("f64"), - Type::Uint32 | Type::Fixed32 => String::from("u32"), - Type::Uint64 | Type::Fixed64 => String::from("u64"), - Type::Int32 | Type::Sfixed32 | Type::Sint32 | Type::Enum => String::from("i32"), - Type::Int64 | Type::Sfixed64 | Type::Sint64 => String::from("i64"), - Type::Bool => String::from("bool"), - Type::String => String::from("::prost::alloc::string::String"), - Type::Bytes => String::from("::prost::alloc::vec::Vec"), - Type::Group | Type::Message => self.resolve_ident(field.type_name()), - }; - let ty = if self.boxed_decoration() { - format!("::prost::alloc::boxed::Box<{ty}>") - } else { - ty - }; - if self.optional(field) { - format!("Option<{ty}>") - } else if field.label() == Label::Repeated { - format!("::prost::alloc::vec::Vec<{ty}>") - } else { - ty - } - } - - fn resolve_ident(&self, pb_ident: &str) -> String { - // protoc should always give fully qualified identifiers. - assert_eq!(".", &pb_ident[..1]); - - let mut local_path = self.package.split('.').peekable(); - - let mut ident_path = pb_ident[1..].split('.'); - let ident_type = ident_path.next_back().unwrap(); - let mut ident_path = ident_path.peekable(); - - // Skip path elements in common. - while local_path.peek().is_some() && local_path.peek() == ident_path.peek() { - local_path.next(); - ident_path.next(); - } - - local_path - .map(|_| "super".to_string()) - .chain(ident_path.map(to_snake)) - .chain(std::iter::once(to_upper_camel(ident_type))) - .join("::") - } -} - -/// Converts a `camelCase` or `SCREAMING_SNAKE_CASE` identifier to a `lower_snake` case Rust field -/// identifier. -pub fn to_snake(s: &str) -> String { - let mut ident = s.to_snake_case(); - - // Use a raw identifier if the identifier matches a Rust keyword: - // https://doc.rust-lang.org/reference/keywords.html. - match ident.as_str() { - // 2015 strict keywords. - | "as" | "break" | "const" | "continue" | "else" | "enum" | "false" - | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | "match" | "mod" | "move" | "mut" - | "pub" | "ref" | "return" | "static" | "struct" | "trait" | "true" - | "type" | "unsafe" | "use" | "where" | "while" - // 2018 strict keywords. - | "dyn" - // 2015 reserved keywords. - | "abstract" | "become" | "box" | "do" | "final" | "macro" | "override" | "priv" | "typeof" - | "unsized" | "virtual" | "yield" - // 2018 reserved keywords. - | "async" | "await" | "try" => ident.insert_str(0, "r#"), - // the following keywords are not supported as raw identifiers and are therefore suffixed with an underscore. - "self" | "super" | "extern" | "crate" => ident += "_", - _ => (), - } - ident -} - -/// Converts a `snake_case` identifier to an `UpperCamel` case Rust type identifier. -pub fn to_upper_camel(s: &str) -> String { - let mut ident = s.to_upper_camel_case(); - - // Suffix an underscore for the `Self` Rust keyword as it is not allowed as raw identifier. - if ident == "Self" { - ident += "_"; - } - ident -} - -pub fn extend_types( - file_descriptor_set_path: impl AsRef, - out_file: impl AsRef, - mod_prefix: &str, - type_prefix: &str, -) { - use prost::Message; - let buf = std::fs::read(file_descriptor_set_path).unwrap(); - let file_descriptor_set = FileDescriptorSet::decode(&*buf).unwrap(); - let mut buf = String::new(); - buf.push_str( - r#" - #![allow(clippy::too_many_arguments)] - - use ::prpc::codec::scale::{Encode, Decode, Error as ScaleDecodeError}; - use ::alloc::vec::Vec; - use ::alloc::string::String; - "#, - ); - if !mod_prefix.is_empty() { - buf.push_str(&format!("use {mod_prefix}*;\n")); - } - for file in file_descriptor_set.file { - CodeGenerator::generate(file, &mut buf, mod_prefix, type_prefix); - } - std::fs::write(out_file, buf).unwrap(); -} diff --git a/crates/prpc-build/src/server.rs b/crates/prpc-build/src/server.rs deleted file mode 100644 index 1125682be0..0000000000 --- a/crates/prpc-build/src/server.rs +++ /dev/null @@ -1,290 +0,0 @@ -use super::{Attributes, Method, Service}; -use crate::{generate_doc_comment, generate_doc_comments, naive_snake_case}; -use proc_macro2::{Span, TokenStream}; -use quote::quote; -use syn::{Ident, Lit, LitStr}; - -/// Generate service for Server. -/// -/// This takes some `Service` and will generate a `TokenStream` that contains -/// a public module containing the server service and handler trait. -pub fn generate( - service: &T, - emit_package: bool, - proto_path: &str, - compile_well_known_types: bool, - attributes: &Attributes, -) -> TokenStream { - let methods = generate_methods( - service, - proto_path, - emit_package, - compile_well_known_types, - false, - ); - let json_methods = generate_methods( - service, - proto_path, - emit_package, - compile_well_known_types, - true, - ); - - let server_service = quote::format_ident!("{}Server", service.name()); - let server_trait = quote::format_ident!("{}", service.name()); - let server_mod = quote::format_ident!("{}_server", naive_snake_case(service.name())); - let supported_methods = generate_supported_methods(service, emit_package); - let method_enum = generate_methods_enum(service, emit_package); - let generated_trait = generate_trait( - service, - proto_path, - compile_well_known_types, - server_trait.clone(), - ); - let service_doc = generate_doc_comments(service.comment()); - let package = if emit_package { service.package() } else { "" }; - let path = crate::join_path(emit_package, service.package(), service.identifier(), ""); - let mod_attributes = attributes.for_mod(package); - let struct_attributes = attributes.for_struct(&path); - - quote! { - /// Generated server implementations. - #(#mod_attributes)* - pub mod #server_mod { - use alloc::vec::Vec; - use alloc::boxed::Box; - - #method_enum - - #supported_methods - - #generated_trait - - #service_doc - #(#struct_attributes)* - #[derive(Debug)] - pub struct #server_service { - inner: T, - } - - impl #server_service { - pub fn new(inner: T) -> Self { - Self { - inner, - } - } - - pub async fn dispatch_request(&mut self, path: &str, data: impl AsRef<[u8]>) -> Result, prpc::server::Error> { - #![allow(clippy::let_unit_value)] - match path { - #methods - _ => Err(prpc::server::Error::NotFound), - } - } - - pub async fn dispatch_json_request(&mut self, path: &str, data: impl AsRef<[u8]>) -> Result, prpc::server::Error> { - #![allow(clippy::let_unit_value)] - match path { - #json_methods - _ => Err(prpc::server::Error::NotFound), - } - } - } - } - } -} - -fn generate_trait( - service: &T, - proto_path: &str, - compile_well_known_types: bool, - server_trait: Ident, -) -> TokenStream { - let methods = generate_trait_methods(service, proto_path, compile_well_known_types); - let trait_doc = generate_doc_comment(format!( - "Generated trait containing RPC methods that should be implemented for use with {}Server.", - service.name() - )); - - quote! { - #trait_doc - #[async_trait::async_trait] - pub trait #server_trait { - #methods - } - } -} - -fn generate_trait_methods( - service: &T, - proto_path: &str, - compile_well_known_types: bool, -) -> TokenStream { - let mut stream = TokenStream::new(); - - for method in service.methods() { - let name = quote::format_ident!("{}", method.name()); - - let (req_message, res_message) = - method.request_response_name(proto_path, compile_well_known_types); - - let method_doc = generate_doc_comments(method.comment()); - - let method = match (method.client_streaming(), method.server_streaming()) { - (false, false) => { - quote! { - #method_doc - async fn #name(&mut self, request: #req_message) - -> Result<#res_message, prpc::server::Error>; - } - } - _ => { - panic!("Streaming RPC not supported"); - } - }; - - stream.extend(method); - } - - stream -} - -fn generate_supported_methods(service: &T, emit_package: bool) -> TokenStream { - let mut all_methods = TokenStream::new(); - for method in service.methods() { - let path = crate::join_path( - emit_package, - service.package(), - service.identifier(), - method.identifier(), - ); - - let method_path = Lit::Str(LitStr::new(&path, Span::call_site())); - all_methods.extend(quote! { - #method_path, - }); - } - - quote! { - pub fn supported_methods() - -> &'static [&'static str] { - &[ - #all_methods - ] - } - } -} - -fn generate_methods_enum(service: &T, emit_package: bool) -> TokenStream { - let mut paths = vec![]; - let mut variants = vec![]; - for method in service.methods() { - let path = crate::join_path( - emit_package, - service.package(), - service.identifier(), - method.identifier(), - ); - - let variant = Ident::new(method.identifier(), Span::call_site()); - variants.push(variant); - - let method_path = Lit::Str(LitStr::new(&path, Span::call_site())); - paths.push(method_path); - } - - let enum_name = Ident::new( - &format!("{}Method", service.identifier()), - Span::call_site(), - ); - quote! { - pub enum #enum_name { - #(#variants,)* - } - - impl #enum_name { - #[allow(clippy::should_implement_trait)] - pub fn from_str(path: &str) -> Option { - match path { - #(#paths => Some(Self::#variants),)* - _ => None, - } - } - } - } -} - -fn generate_methods( - service: &T, - proto_path: &str, - emit_package: bool, - compile_well_known_types: bool, - json: bool, -) -> TokenStream { - let mut stream = TokenStream::new(); - - for method in service.methods() { - let path = crate::join_path( - emit_package, - service.package(), - service.identifier(), - method.identifier(), - ); - let method_path = Lit::Str(LitStr::new(&path, Span::call_site())); - let method_ident = quote::format_ident!("{}", method.name()); - let server_trait = quote::format_ident!("{}", service.name()); - - let method_stream = match (method.client_streaming(), method.server_streaming()) { - (false, false) => generate_unary( - method, - proto_path, - compile_well_known_types, - method_ident, - server_trait, - json, - ), - _ => { - panic!("Streaming RPC not supported"); - } - }; - - let method = quote! { - #method_path => { - #method_stream - } - }; - stream.extend(method); - } - - stream -} - -fn generate_unary( - method: &T, - proto_path: &str, - compile_well_known_types: bool, - method_ident: Ident, - _server_trait: Ident, - json: bool, -) -> TokenStream { - let (request, _response) = method.request_response_name(proto_path, compile_well_known_types); - - if json { - quote! { - let data = data.as_ref(); - let input: #request = if data.is_empty() { - Default::default() - } else { - serde_json::from_slice(data)? - }; - let response = self.inner.#method_ident(input).await?; - Ok(serde_json::to_vec(&response)?) - } - } else { - quote! { - let input: #request = prpc::Message::decode(data.as_ref())?; - let response = self.inner.#method_ident(input).await?; - Ok(prpc::codec::encode_message_to_vec(&response)) - } - } -} diff --git a/crates/prpc/Cargo.toml b/crates/prpc/Cargo.toml deleted file mode 100644 index 37c7ce4806..0000000000 --- a/crates/prpc/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "prpc" -version = "0.1.0" -edition = "2018" - -[dependencies] -async-trait = "0.1.57" -derive_more = "0.99.16" -prost = { version = "0.11", default-features = false, features = ["prost-derive"] } -anyhow = { version = "1", default-features = false } -parity-scale-codec = { version = "3.6.5", default-features = false } -serde_json = { version = "1", default-features = false } - -[features] -default = ["std"] -std = ["serde_json/std"] diff --git a/crates/prpc/src/lib.rs b/crates/prpc/src/lib.rs deleted file mode 100644 index eaa273afa1..0000000000 --- a/crates/prpc/src/lib.rs +++ /dev/null @@ -1,125 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -extern crate alloc; - -use alloc::boxed::Box; -use alloc::string::String; -use alloc::vec::Vec; -use async_trait::async_trait; -use derive_more::Display; -use prost::DecodeError; - -pub use prost::Message; - -pub mod server { - use super::*; - use alloc::string::ToString; - use parity_scale_codec::Error as ScaleCodecErr; - - /// Error for server side RPC handlers. Finally, this error will be wrapped in a `ProtoError`. - #[derive(Display, Debug)] - pub enum Error { - /// The requesting RPC method is not recognized - NotFound, - /// Failed to decode the request parameters - DecodeError(DecodeError), - /// Some error occurred when handling the request - AppError(String), - /// Error for contract query - #[display(fmt = "ContractQueryError({_0})")] - ContractQueryError(String), - } - - impl From for Error { - fn from(e: DecodeError) -> Self { - Self::DecodeError(e) - } - } - - #[cfg(feature = "std")] - impl std::error::Error for Error {} - - #[cfg(not(feature = "std"))] - impl From for anyhow::Error { - fn from(error: Error) -> Self { - Self::msg(error) - } - } - - impl From for Error { - fn from(e: ScaleCodecErr) -> Self { - Self::DecodeError(DecodeError::new(e.to_string())) - } - } - - impl From for Error { - fn from(e: serde_json::Error) -> Self { - Self::DecodeError(DecodeError::new(e.to_string())) - } - } - - /// The final Error type of RPCs to be serialized to protobuf. - #[derive(Display, Message)] - pub struct ProtoError { - #[prost(string, tag = "1")] - pub message: ::prost::alloc::string::String, - } - - impl ProtoError { - pub fn new(message: impl Into) -> ProtoError { - ProtoError { - message: message.into(), - } - } - } -} - -pub mod client { - use super::*; - - /// The Error type for the generated client-side RPCs. - #[derive(Display, Debug)] - pub enum Error { - /// Failed to decode the response from the server. - DecodeError(DecodeError), - /// The error returned by the server. - ServerError(super::server::ProtoError), - /// Other errors sush as networking error. - RpcError(String), - } - - impl From for Error { - fn from(e: DecodeError) -> Self { - Self::DecodeError(e) - } - } - - #[cfg(feature = "std")] - impl std::error::Error for Error {} - - #[cfg(not(feature = "std"))] - impl From for anyhow::Error { - fn from(error: Error) -> Self { - Self::msg(error) - } - } - - /// Trait for RPC client to implement the underlying data transport. - /// Required by the generated RPC client. - #[async_trait] - pub trait RequestClient { - async fn request(&self, path: &str, body: Vec) -> Result, Error>; - } -} - -pub mod codec { - use super::*; - - pub use parity_scale_codec as scale; - - pub fn encode_message_to_vec(msg: &impl Message) -> Vec { - let mut buf = Vec::with_capacity(msg.encoded_len()); - - msg.encode_raw(&mut buf); - buf - } -} diff --git a/crates/rustfmt-snippet/Cargo.toml b/crates/rustfmt-snippet/Cargo.toml index 545d4a7f26..393ee9b9cb 100644 --- a/crates/rustfmt-snippet/Cargo.toml +++ b/crates/rustfmt-snippet/Cargo.toml @@ -8,5 +8,3 @@ edition = "2018" [dependencies] proc-macro2 = "1.0.36" -tempfile = "3.10.1" - diff --git a/crates/rustfmt-snippet/src/lib.rs b/crates/rustfmt-snippet/src/lib.rs index d9986dfb51..a4554d33f4 100644 --- a/crates/rustfmt-snippet/src/lib.rs +++ b/crates/rustfmt-snippet/src/lib.rs @@ -16,18 +16,8 @@ pub fn rustfmt(source: &str) -> std::io::Result { io::Write, process::{Command, Stdio}, }; - use tempfile::NamedTempFile; - // Create a temporary file - let mut tempfile: NamedTempFile = NamedTempFile::new()?; - - // Write the source code to the temporary file - writeln!(tempfile, "{}", source)?; - - // Retrieve the path of the temporary file to pass it to rustfmt - let path = tempfile.path(); - let path = format!("{}", path.display()); let proc = Command::new("rustfmt") - .args([path.as_str(), "--emit", "stdout", "--edition", "2018"]) + .args(["--emit", "stdout", "--edition", "2018"]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn()?;