diff --git a/Cargo.lock b/Cargo.lock index dc5fcbe0cab..9247144f24c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anes" version = "0.1.6" @@ -309,6 +324,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +[[package]] +name = "bstr" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "bumpalo" version = "3.11.1" @@ -384,6 +409,40 @@ dependencies = [ "zeroize", ] +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.48.0", +] + +[[package]] +name = "chrono-tz" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf 0.11.2", +] + +[[package]] +name = "chrono-tz-build" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" +dependencies = [ + "parse-zoneinfo", + "phf 0.11.2", + "phf_codegen 0.11.2", +] + [[package]] name = "ciborium" version = "0.2.0" @@ -1165,7 +1224,7 @@ dependencies = [ "ckb-types", "includedir", "includedir_codegen", - "phf", + "phf 0.8.0", "serde", "tempfile", "walkdir", @@ -1258,6 +1317,7 @@ dependencies = [ "ckb-rpc", "schemars", "serde_json", + "tera", ] [[package]] @@ -1424,7 +1484,7 @@ dependencies = [ "faster-hex", "includedir", "includedir_codegen", - "phf", + "phf 0.8.0", ] [[package]] @@ -1671,6 +1731,16 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "console" version = "0.15.5" @@ -1891,6 +1961,50 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cxx" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn 2.0.12", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.12", +] + [[package]] name = "darling" version = "0.14.1" @@ -1965,6 +2079,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "deunicode" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95203a6a50906215a502507c0f879a0ce7ff205a6111e2db2a5ef8e4bb92e43" + [[package]] name = "diff" version = "0.1.13" @@ -2358,6 +2478,30 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "globset" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "globwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + [[package]] name = "goblin" version = "0.2.3" @@ -2555,6 +2699,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "humansize" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" + [[package]] name = "humantime" version = "1.3.0" @@ -2601,6 +2751,30 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2631,6 +2805,23 @@ dependencies = [ "xmltree", ] +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + [[package]] name = "includedir" version = "0.6.0" @@ -2638,7 +2829,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afd126bd778c00c43a9dc76d1609a0894bf4222088088b2217ccc0ce9e816db7" dependencies = [ "flate2", - "phf", + "phf 0.8.0", ] [[package]] @@ -2648,7 +2839,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ac1500c9780957c9808c4ec3b94002f35aab01483833f5a8bce7dfb243e3148" dependencies = [ "flate2", - "phf_codegen", + "phf_codegen 0.8.0", "walkdir", ] @@ -2877,6 +3068,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" +[[package]] +name = "link-cplusplus" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +dependencies = [ + "cc", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -3335,6 +3535,15 @@ dependencies = [ "windows-sys 0.36.1", ] +[[package]] +name = "parse-zoneinfo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +dependencies = [ + "regex", +] + [[package]] name = "paste" version = "1.0.6" @@ -3359,6 +3568,51 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35513f630d46400a977c4cb58f78e1bfbe01434316e60c37d27b9ad6139c66d8" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9fc1b9e7057baba189b5c626e2d6f40681ae5b6eb064dc7c7834101ec8123a" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.12", +] + +[[package]] +name = "pest_meta" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df74e9e7ec4053ceb980e7c0c8bd3594e977fde1af91daba9c928e8e8c6708d" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "petgraph" version = "0.6.0" @@ -3375,7 +3629,16 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" dependencies = [ - "phf_shared", + "phf_shared 0.8.0", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_shared 0.11.2", ] [[package]] @@ -3384,8 +3647,18 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.8.0", + "phf_shared 0.8.0", +] + +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", ] [[package]] @@ -3394,10 +3667,20 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ - "phf_shared", + "phf_shared 0.8.0", "rand 0.7.3", ] +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand 0.8.5", +] + [[package]] name = "phf_shared" version = "0.8.0" @@ -3407,6 +3690,16 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", + "uncased", +] + [[package]] name = "pin-project" version = "1.1.0" @@ -3998,6 +4291,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" + [[package]] name = "scroll" version = "0.10.2" @@ -4293,6 +4592,15 @@ dependencies = [ "parking_lot 0.11.2", ] +[[package]] +name = "slug" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" +dependencies = [ + "deunicode", +] + [[package]] name = "smallvec" version = "1.8.0" @@ -4484,6 +4792,28 @@ dependencies = [ "x25519-dalek", ] +[[package]] +name = "tera" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df578c295f9ec044ff1c829daf31bb7581d5b3c2a7a3d87419afe1f2531438c" +dependencies = [ + "chrono", + "chrono-tz", + "globwalk", + "humansize", + "lazy_static", + "percent-encoding", + "pest", + "pest_derive", + "rand 0.8.5", + "regex", + "serde", + "serde_json", + "slug", + "unic-segment", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -4530,6 +4860,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tikv-jemalloc-ctl" version = "0.5.0" @@ -4867,6 +5207,12 @@ dependencies = [ "serde", ] +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "uname" version = "0.1.1" @@ -4882,6 +5228,65 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "uncased" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b9bc53168a4be7402ab86c3aad243a84dd7381d09be0eddc81280c1da95ca68" +dependencies = [ + "version_check", +] + +[[package]] +name = "unic-char-property" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" +dependencies = [ + "unic-char-range", +] + +[[package]] +name = "unic-char-range" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" + +[[package]] +name = "unic-common" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" + +[[package]] +name = "unic-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" +dependencies = [ + "unic-ucd-segment", +] + +[[package]] +name = "unic-ucd-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" +dependencies = [ + "unic-char-property", + "unic-char-range", + "unic-ucd-version", +] + +[[package]] +name = "unic-ucd-version" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" +dependencies = [ + "unic-common", +] + [[package]] name = "unicode-bidi" version = "0.3.7" @@ -5163,6 +5568,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-sys" version = "0.36.1" diff --git a/devtools/doc/rpc-gen/Cargo.toml b/devtools/doc/rpc-gen/Cargo.toml index 58c5bc7e540..6c0a8420110 100644 --- a/devtools/doc/rpc-gen/Cargo.toml +++ b/devtools/doc/rpc-gen/Cargo.toml @@ -12,3 +12,4 @@ repository = "https://github.com/nervosnetwork/ckb" ckb-rpc ={ path = "../../../rpc", version = "= 0.112.0-pre" } schemars = { git = "https://github.com/chenyukang/schemars", branch = "fix-derive" } serde_json = "~1.0" +tera = "1" \ No newline at end of file diff --git a/devtools/doc/rpc-gen/src/gen.rs b/devtools/doc/rpc-gen/src/gen.rs index 4af594b8f79..59f1238c4c2 100644 --- a/devtools/doc/rpc-gen/src/gen.rs +++ b/devtools/doc/rpc-gen/src/gen.rs @@ -1,123 +1,121 @@ +extern crate tera; use ckb_rpc::RPCError; use schemars::schema_for; use serde_json::{Map, Value}; use std::fs; +use tera::Tera; struct RpcModule { - pub module_title: String, - pub module_description: String, - pub module_methods: Vec, + pub title: String, + pub description: String, + pub methods: Vec, } impl RpcModule { - pub fn gen_module_menu(&self) -> String { - let mut res = String::new(); - let capitlized = self.module_title.to_string(); - res.push_str(&format!( - " * [Module {}](#module-{}) {}\n", - capitlized, - self.module_title.to_lowercase(), - gen_module_openrpc_playground(&capitlized) - )); + pub fn gen_menu(&self) -> (String, String, String, Vec) { + let capitlized = self.title.to_string(); let mut method_names = self - .module_methods + .methods .iter() - .map(|method| method["name"].as_str().unwrap()) + .map(|method| method["name"].as_str().unwrap().to_owned()) .collect::>(); if capitlized == "Subscription" { - method_names.push("subscribe"); - method_names.push("unsubscribe"); + method_names.push("subscribe".to_owned()); + method_names.push("unsubscribe".to_owned()); } - for name in method_names.iter() { - res.push_str(&format!( - " * [Method `{}`](#method-{})\n", - name, name - )); - } - res + ( + capitlized.to_owned(), + self.title.to_lowercase(), + gen_module_openrpc_playground(&capitlized), + method_names, + ) } pub fn gen_module_content(&self) -> String { - let mut res = String::new(); - let capitlized = self.module_title.to_string(); - let description = self.module_description.replace("##", "#####"); - - res.push_str(&format!("### Module {}\n", capitlized)); - res.push_str(&format!( - "- {}\n\n", - gen_module_openrpc_playground(&capitlized) - )); - res.push_str(&format!("{}\n\n", description)); - - for method in &self.module_methods { - // generate method signatures - let name = method["name"].as_str().unwrap(); - let params = method["params"].as_array().unwrap(); - let args = params - .iter() - .map(|arg| arg["name"].as_str().unwrap()) - .collect::>() - .join(", "); - let arg_lines = params - .iter() - .map(|arg| { - let ty = gen_type(&arg["schema"]); - format!(" * `{}`: {}", arg["name"].as_str().unwrap(), ty) - }) - .collect::>() - .join("\n"); - let ret_ty = if let Some(value) = method.get("result") { - format!("* result: {}", gen_type(&value["schema"])) - } else { - "".to_string() - }; - let signatures = format!("* `{}({})`\n{}\n{}", name, args, arg_lines, ret_ty); - let mut desc = method["description"] - .as_str() - .unwrap() - .replace("##", "######"); - desc = strip_prefix_space(&desc); - res.push_str(&format!( - "#### Method `{}`\n{}\n\n{}\n", - name, signatures, desc, - )); + if self.title == "Subscription" { + return gen_subscription_rpc_doc(); } - res + "\n" + let capitlized = self.title.to_string(); + let description = self.description.replace("##", "#####"); + + let methods = self + .methods + .iter() + .map(|method| { + // generate method signatures + let name = method["name"].as_str().unwrap(); + let params = method["params"].as_array().unwrap(); + let args = params + .iter() + .map(|arg| arg["name"].as_str().unwrap()) + .collect::>() + .join(", "); + let arg_lines = params + .iter() + .map(|arg| { + let ty = gen_type(&arg["schema"]); + format!(" * `{}`: {}", arg["name"].as_str().unwrap(), ty) + }) + .collect::>() + .join("\n"); + let ret_ty = if let Some(value) = method.get("result") { + format!("* result: {}", gen_type(&value["schema"])) + } else { + "".to_string() + }; + let signatures = format!("* `{}({})`\n{}\n{}", name, args, arg_lines, ret_ty); + let mut desc = method["description"] + .as_str() + .unwrap() + .replace("##", "######"); + desc = strip_prefix_space(&desc); + format!("#### Method `{}`\n{}\n\n{}\n", name, signatures, desc,) + }) + .collect::>(); + let mut tera = Tera::default(); + tera.add_raw_template("module", include_str!("../templates/module")) + .unwrap(); + let mut context = tera::Context::new(); + context.insert("name", &capitlized); + context.insert("link", &gen_module_openrpc_playground(&capitlized)); + context.insert("desc", &description); + context.insert("methods", &methods); + tera.render("module", &context).unwrap() } } pub(crate) struct RpcDocGenerator { - rpc_module_methods: Vec, + rpc_methods: Vec, types: Vec<(String, Value)>, file_path: String, } impl RpcDocGenerator { pub fn new(all_rpc: &Vec, readme_path: String) -> Self { - let mut rpc_module_methods = vec![]; + let mut rpc_methods = vec![]; let mut all_types: Vec<&Map> = vec![]; for rpc in all_rpc { if let serde_json::Value::Object(map) = rpc { - let module_title = capitlize( + let title = capitlize( map["info"]["title"] .as_str() .unwrap() .trim_end_matches("_rpc"), ); - let module_description = get_description(&map["info"]["description"]); - let module_methods = map["methods"].as_array().unwrap(); + let description = get_description(&map["info"]["description"]); + let methods = map["methods"].as_array().unwrap(); let types = map["components"]["schemas"].as_object().unwrap(); all_types.push(types); - rpc_module_methods.push(RpcModule { - module_title, - module_description, - module_methods: module_methods.to_owned(), + rpc_methods.push(RpcModule { + title, + description, + methods: methods.to_owned(), }); } } - // sort rpc_module_methods accoring to module_title - rpc_module_methods.sort_by(|a, b| a.module_title.cmp(&b.module_title)); + // sort rpc_methods accoring to title + rpc_methods.sort_by(|a, b| a.title.cmp(&b.title)); let mut types: Vec<(String, Value)> = vec![]; for map in all_types.iter() { @@ -130,85 +128,84 @@ impl RpcDocGenerator { types.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); Self { - rpc_module_methods, + rpc_methods, types, file_path: readme_path, } } pub fn gen_markdown(self) -> String { - let mut res = String::new(); + let mut tera = Tera::default(); + + let template = include_str!("../templates/markdown"); + tera.add_raw_template("markdown", template).unwrap(); - // strip lines below `**NOTE:**` let readme = fs::read_to_string(&self.file_path).unwrap_or("".to_string()); let lines = readme.lines().collect::>(); - for &line in lines.iter() { - res.push_str(&(line.to_string() + "\n")); - if line.contains("**NOTE:** the content below is generated by gen_doc") { - break; - } - } + let summary = lines + .iter() + .take_while(|l| !l.contains("**NOTE:** the content below is generated by gen_doc")) + .map(|l| l.to_string()) + .collect::>() + .join("\n"); // generate methods menu - res.push_str("\n\n* [RPC Methods](#rpc-methods)\n"); - for rpc_module in self.rpc_module_methods.iter() { - res.push_str(&rpc_module.gen_module_menu()); - } + let module_menus = self + .rpc_methods + .iter() + .map(|r| r.gen_menu()) + .collect::>(); - // generate type menu - res.push_str("* [RPC Types](#rpc-types)\n"); - for (name, _) in self.types.iter() { - let ty = format!( - " * [Type `{}`](#type-{})\n", - capitlize(name), - name.to_lowercase() - ); - res.push_str(&ty); - } - // generate error menu - res.push_str("* [RPC Errors](#rpc-errors)\n"); + let type_menus = self + .types + .iter() + .map(|(name, _)| (capitlize(name), name.to_lowercase())) + .collect::>(); // generate module methods content - for rpc_module in self.rpc_module_methods.iter() { - if rpc_module.module_title == "Subscription" { - gen_subscription_rpc_doc(&mut res); - } else { - res.push_str(&rpc_module.gen_module_content()); - } - } + let modules = self + .rpc_methods + .iter() + .map(|r| r.gen_module_content()) + .collect::>(); - // generate type content - res.push_str("## RPC Types\n"); - self.gen_type_content(&mut res); + let types = self.gen_type_contents(); - gen_errors_content(&mut res); - res + let mut context = tera::Context::new(); + context.insert("summary", &summary); + context.insert("module_menus", &module_menus); + context.insert("type_menus", &type_menus); + context.insert("modules", &modules); + context.insert("types", &types); + context.insert("errors", &gen_errors_contents()); + tera.render("markdown", &context).unwrap() } - fn gen_type_content(&self, res: &mut String) { - for (name, ty) in self.types.iter() { - let desc = if let Some(desc) = ty.get("description") { - desc.as_str().unwrap().to_string() - } else if let Some(desc) = ty.get("format") { - format!("`{}` is `{}`", name, desc.as_str().unwrap()) - } else { - "".to_string() - }; - let desc = desc.replace("##", "######"); - // remove the inline code from comments - let desc = desc - .lines() - .filter(|l| !l.contains("serde_json::from_str") && !l.contains(".unwrap()")) - .collect::>() - .join("\n"); - - // replace only the first ``` with ```json - let desc = desc.replacen("```\n", "```json\n", 1); + fn gen_type_contents(&self) -> Vec<(String, String, String)> { + self.types + .iter() + .map(|(name, ty)| { + let desc = if let Some(desc) = ty.get("description") { + desc.as_str().unwrap().to_string() + } else if let Some(desc) = ty.get("format") { + format!("`{}` is `{}`", name, desc.as_str().unwrap()) + } else { + "".to_string() + }; + let desc = desc.replace("##", "######"); + // remove the inline code from comments + let desc = desc + .lines() + .filter(|l| !l.contains("serde_json::from_str") && !l.contains(".unwrap()")) + .collect::>() + .join("\n"); - let fileds = gen_type_fields(ty); - let type_desc = format!("### Type `{}`\n{}\n{}\n\n", capitlize(name), desc, fileds); - res.push_str(&type_desc); - } + // replace only the first ``` with ```json + let desc = desc.replacen("```\n", "```json\n", 1); + let fields = gen_type_fields(ty); + (capitlize(name), desc, fields) + }) + .collect::>() } } @@ -358,24 +355,26 @@ fn gen_type(ty: &Value) -> String { } } -fn gen_errors_content(res: &mut String) { +fn gen_errors_contents() -> (String, Vec<(String, String)>) { let schema = schema_for!(RPCError); let value = serde_json::to_value(schema).unwrap(); let summary = get_description(&value["description"]); - res.push_str("## RPC Errors\n"); - res.push_str(&summary); - - for error in value["oneOf"].as_array().unwrap().iter() { - let desc = get_description(&error["description"]); - let enum_ty = error["enum"].as_array().unwrap()[0].as_str().unwrap(); - let doc = format!("\n### ERROR `{}`\n{}\n", enum_ty, desc); - res.push_str(&doc); - } + let errors = value["oneOf"] + .as_array() + .unwrap() + .iter() + .map(|error| { + let desc = get_description(&error["description"]); + let enum_ty = error["enum"].as_array().unwrap()[0].as_str().unwrap(); + (enum_ty.to_string(), desc) + }) + .collect::>(); + (summary, errors) } /// generate subscription module, which is handled specially here /// since jsonrpc-utils ignore the `SubscriptionRpc` -fn gen_subscription_rpc_doc(res: &mut String) { +fn gen_subscription_rpc_doc() -> String { let pubsub_module_source = include_str!("../../../../rpc/src/module/subscription.rs"); // read comments before `pub trait SubscriptionRpc` and treat it as module summary let summary = pubsub_module_source @@ -405,37 +404,17 @@ fn gen_subscription_rpc_doc(res: &mut String) { .join("\n"); let sub_desc = strip_prefix_space(&sub_desc); - res.push_str(format!("{}\n\n", summary).as_str()); - res.push_str(format!("{}\n", sub_desc).as_str()); + format!("{}\n\n{}\n", summary, sub_desc) } /// generate openrpc playground urls fn gen_module_openrpc_playground(module: &str) -> String { - let logo = "https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg"; + let mut tera = Tera::default(); + tera.add_raw_template("link", include_str!("../templates/link")) + .unwrap(); let title = format!("CKB-{}", capitlize(module)); - let json_url = format!( - "https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/{}_rpc_doc.json", - module.to_lowercase() - ); - - format!("[👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]={}&uiSchema[appBar][ui:splitView]=false", title) + - format!("&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]={}&schemaUrl={})", logo, json_url).as_str() -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_strip_prefix_space() { - assert_eq!(strip_prefix_space(" "), "".to_string()); - assert_eq!( - strip_prefix_space(" \n abc\n cdf"), - "\nabc\ncdf".to_string() - ); - assert_eq!( - strip_prefix_space("abc\n cde\n cdf"), - "abc\n cde\n cdf".to_string() - ); - } + let mut context = tera::Context::new(); + context.insert("title", &title); + context.insert("module", &module.to_lowercase()); + tera.render("link", &context).unwrap() } diff --git a/devtools/doc/rpc-gen/templates/link b/devtools/doc/rpc-gen/templates/link new file mode 100644 index 00000000000..2c66c704b31 --- /dev/null +++ b/devtools/doc/rpc-gen/templates/link @@ -0,0 +1 @@ +[👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]={{title}}&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/{{module}}_rpc_doc.json) \ No newline at end of file diff --git a/devtools/doc/rpc-gen/templates/markdown b/devtools/doc/rpc-gen/templates/markdown new file mode 100644 index 00000000000..b9ffe3ae49d --- /dev/null +++ b/devtools/doc/rpc-gen/templates/markdown @@ -0,0 +1,31 @@ +{{ summary }} + + +* [RPC Methods](#rpc-methods) +{% for menu in module_menus %} +{% set methods = menu.3 %} + * [Module {{menu.0}}](#module-{{menu.1}}) {{menu.2}} +{% for method in methods %} * [Method `{{method}}`](#method-{{method}}) +{% endfor %}{% endfor %} +* [RPC Types](#rpc-types) +{% for menu in type_menus %} + * [Type `{{ menu.0 }}`](#type-{{ menu.1 }}){% endfor %} +* [RPC Errors](#rpc-errors) + +## RPC Modules +{% for module in modules %} +{{module}}{% endfor %} + +## RPC Types +{% for ty in types %} +### Type `{{ty.0}}` +{{ty.1}} +{{ty.2}} +{% endfor %} + +## RPC Errors +{{errors.0}} +{% for error in errors.1 %} +### ERROR `{{error.0}}` +{{error.1}} +{% endfor %} \ No newline at end of file diff --git a/devtools/doc/rpc-gen/templates/module b/devtools/doc/rpc-gen/templates/module new file mode 100644 index 00000000000..fed084d690e --- /dev/null +++ b/devtools/doc/rpc-gen/templates/module @@ -0,0 +1,6 @@ +### Module `{{name}}` +- {{link}} + +{{desc}} +{% for method in methods %} +{{method}}{% endfor %} \ No newline at end of file diff --git a/rpc/README.md b/rpc/README.md index 4e7cdc2f12e..073f50bdba0 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -29,10 +29,13 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. - * [RPC Methods](#rpc-methods) + + * [Module Alert](#module-alert) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Alert&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/alert_rpc_doc.json) * [Method `send_alert`](#method-send_alert) + + * [Module Chain](#module-chain) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Chain&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/chain_rpc_doc.json) * [Method `get_block`](#method-get_block) * [Method `get_block_by_number`](#method-get_block_by_number) @@ -57,18 +60,26 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Method `estimate_cycles`](#method-estimate_cycles) * [Method `get_fee_rate_statics`](#method-get_fee_rate_statics) * [Method `get_fee_rate_statistics`](#method-get_fee_rate_statistics) + + * [Module Debug](#module-debug) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Debug&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/debug_rpc_doc.json) * [Method `jemalloc_profiling_dump`](#method-jemalloc_profiling_dump) * [Method `update_main_logger`](#method-update_main_logger) * [Method `set_extra_logger`](#method-set_extra_logger) + + * [Module Experiment](#module-experiment) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Experiment&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/experiment_rpc_doc.json) * [Method `dry_run_transaction`](#method-dry_run_transaction) * [Method `calculate_dao_maximum_withdraw`](#method-calculate_dao_maximum_withdraw) + + * [Module Indexer](#module-indexer) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Indexer&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/indexer_rpc_doc.json) * [Method `get_indexer_tip`](#method-get_indexer_tip) * [Method `get_cells`](#method-get_cells) * [Method `get_transactions`](#method-get_transactions) * [Method `get_cells_capacity`](#method-get_cells_capacity) + + * [Module Integration_test](#module-integration_test) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Integration_test&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/integration_test_rpc_doc.json) * [Method `process_block_without_verify`](#method-process_block_without_verify) * [Method `truncate`](#method-truncate) @@ -77,9 +88,13 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Method `notify_transaction`](#method-notify_transaction) * [Method `generate_block_with_template`](#method-generate_block_with_template) * [Method `calculate_dao_field`](#method-calculate_dao_field) + + * [Module Miner](#module-miner) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Miner&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/miner_rpc_doc.json) * [Method `get_block_template`](#method-get_block_template) * [Method `submit_block`](#method-submit_block) + + * [Module Net](#module-net) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Net&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/net_rpc_doc.json) * [Method `local_node_info`](#method-local_node_info) * [Method `get_peers`](#method-get_peers) @@ -91,6 +106,8 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Method `add_node`](#method-add_node) * [Method `remove_node`](#method-remove_node) * [Method `ping_peers`](#method-ping_peers) + + * [Module Pool](#module-pool) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Pool&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/pool_rpc_doc.json) * [Method `send_transaction`](#method-send_transaction) * [Method `remove_transaction`](#method-remove_transaction) @@ -98,13 +115,19 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Method `clear_tx_pool`](#method-clear_tx_pool) * [Method `get_raw_tx_pool`](#method-get_raw_tx_pool) * [Method `tx_pool_ready`](#method-tx_pool_ready) + + * [Module Stats](#module-stats) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Stats&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/stats_rpc_doc.json) * [Method `get_blockchain_info`](#method-get_blockchain_info) * [Method `get_deployments_info`](#method-get_deployments_info) + + * [Module Subscription](#module-subscription) [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Subscription&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/subscription_rpc_doc.json) * [Method `subscribe`](#method-subscribe) * [Method `unsubscribe`](#method-unsubscribe) + * [RPC Types](#rpc-types) + * [Type `Alert`](#type-alert) * [Type `AlertId`](#type-alertid) * [Type `AlertMessage`](#type-alertmessage) @@ -199,7 +222,10 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Type `UncleBlockView`](#type-uncleblockview) * [Type `UncleTemplate`](#type-uncletemplate) * [RPC Errors](#rpc-errors) -### Module Alert + +## RPC Modules + +### Module `Alert` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Alert&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/alert_rpc_doc.json) RPC Module Alert for network alerts. @@ -264,7 +290,7 @@ Response } ``` -### Module Chain +### Module `Chain` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Chain&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/chain_rpc_doc.json) RPC Module Chain for methods related to the canonical chain. @@ -420,6 +446,7 @@ When specifying with_cycles, the response object will be different like below: } } ``` + #### Method `get_block_by_number` * `get_block_by_number(block_number, verbosity, with_cycles)` * `block_number`: [`Uint64`](#type-uint64) @@ -553,6 +580,7 @@ When specifying with_cycles, the response object will be different like below: } } ``` + #### Method `get_header` * `get_header(block_hash, verbosity)` * `block_hash`: [`H256`](#type-h256) @@ -630,6 +658,7 @@ The response looks like below when `verbosity` is 0. "result": "0x..." } ``` + #### Method `get_header_by_number` * `get_header_by_number(block_number, verbosity)` * `block_number`: [`Uint64`](#type-uint64) @@ -710,6 +739,7 @@ The response looks like below when `verbosity` is 0. "result": "0x..." } ``` + #### Method `get_block_filter` * `get_block_filter(block_hash)` * `block_hash`: [`H256`](#type-h256) @@ -762,6 +792,7 @@ The response looks like below when the block have block filter. } } ``` + #### Method `get_transaction` * `get_transaction(tx_hash, verbosity, only_committed)` * `tx_hash`: [`H256`](#type-h256) @@ -887,6 +918,7 @@ The response looks like below when `verbosity` is 0. } } ``` + #### Method `get_block_hash` * `get_block_hash(block_number)` * `block_number`: [`Uint64`](#type-uint64) @@ -932,6 +964,7 @@ Response "result": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40" } ``` + #### Method `get_tip_header` * `get_tip_header(verbosity)` * `verbosity`: [`AlertId`](#type-alertid) `|` `null` @@ -1000,6 +1033,7 @@ The response looks like below when `verbosity` is 0. "result": "0x..." } ``` + #### Method `get_live_cell` * `get_live_cell(out_point, with_data)` * `out_point`: [`OutPoint`](#type-outpoint) @@ -1069,6 +1103,7 @@ Response } } ``` + #### Method `get_tip_block_number` * `get_tip_block_number()` @@ -1101,6 +1136,7 @@ Response "result": "0x400" } ``` + #### Method `get_current_epoch` * `get_current_epoch()` @@ -1139,6 +1175,7 @@ Response } } ``` + #### Method `get_epoch_by_number` * `get_epoch_by_number(epoch_number)` * `epoch_number`: [`Uint64`](#type-uint64) @@ -1187,6 +1224,7 @@ Response } } ``` + #### Method `get_block_economic_state` * `get_block_economic_state(block_hash)` * `block_hash`: [`H256`](#type-h256) @@ -1253,6 +1291,7 @@ Response } } ``` + #### Method `get_transaction_proof` * `get_transaction_proof(tx_hashes, block_hash)` * `tx_hashes`: `Array<` [`H256`](#type-h256) `>` @@ -1297,6 +1336,7 @@ Response } } ``` + #### Method `verify_transaction_proof` * `verify_transaction_proof(tx_proof)` * `tx_proof`: [`TransactionProof`](#type-transactionproof) @@ -1341,6 +1381,7 @@ Response ] } ``` + #### Method `get_transaction_and_witness_proof` * `get_transaction_and_witness_proof(tx_hashes, block_hash)` * `tx_hashes`: `Array<` [`H256`](#type-h256) `>` @@ -1390,6 +1431,7 @@ Response "id": 42 } ``` + #### Method `verify_transaction_and_witness_proof` * `verify_transaction_and_witness_proof(tx_proof)` * `tx_proof`: [`TransactionAndWitnessProof`](#type-transactionandwitnessproof) @@ -1439,6 +1481,7 @@ Response ] } ``` + #### Method `get_fork_block` * `get_fork_block(block_hash, verbosity)` * `block_hash`: [`H256`](#type-h256) @@ -1553,6 +1596,7 @@ The response looks like below when `verbosity` is 0. "result": "0x..." } ``` + #### Method `get_consensus` * `get_consensus()` @@ -1645,6 +1689,7 @@ Response } } ``` + #### Method `get_block_median_time` * `get_block_median_time(block_hash)` * `block_hash`: [`H256`](#type-h256) @@ -1687,6 +1732,7 @@ Response "result": "0x5cd2b105" } ``` + #### Method `estimate_cycles` * `estimate_cycles(tx)` * `tx`: [`Transaction`](#type-transaction) @@ -1768,6 +1814,7 @@ Response } } ``` + #### Method `get_fee_rate_statics` * `get_fee_rate_statics(target)` * `target`: [`Uint64`](#type-uint64) `|` `null` @@ -1812,6 +1859,7 @@ Response } } ``` + #### Method `get_fee_rate_statistics` * `get_fee_rate_statistics(target)` * `target`: [`Uint64`](#type-uint64) `|` `null` @@ -1857,7 +1905,7 @@ Response } ``` -### Module Debug +### Module `Debug` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Debug&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/debug_rpc_doc.json) RPC Module Debug for internal RPC methods. @@ -1875,12 +1923,14 @@ Dumps jemalloc memory profiling information into a file. The file is stored in the server running the CKB node. The RPC returns the path to the dumped file on success or returns an error on failure. + #### Method `update_main_logger` * `update_main_logger(config)` * `config`: [`MainLoggerConfig`](#type-mainloggerconfig) * result: `null` Changes main logger config options while CKB is running. + #### Method `set_extra_logger` * `set_extra_logger(name, config_opt)` * `name`: `string` @@ -1898,7 +1948,7 @@ they only append logs to their log files. * `config_opt` - Adds a new logger or update an existing logger when this is not null. Removes the logger when this is null. -### Module Experiment +### Module `Experiment` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Experiment&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/experiment_rpc_doc.json) RPC Module Experiment for experimenting methods. @@ -1988,6 +2038,7 @@ Response } } ``` + #### Method `calculate_dao_maximum_withdraw` * `calculate_dao_maximum_withdraw(out_point, kind)` * `out_point`: [`OutPoint`](#type-outpoint) @@ -2049,7 +2100,7 @@ Response } ``` -### Module Indexer +### Module `Indexer` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Indexer&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/indexer_rpc_doc.json) RPC Module Indexer. @@ -2089,6 +2140,7 @@ Response "id": 2 } ``` + #### Method `get_cells` * `get_cells(search_key, order, limit, after)` * `search_key`: [`IndexerSearchKey`](#type-indexersearchkey) @@ -2440,6 +2492,7 @@ Response "id": 2 } ``` + #### Method `get_transactions` * `get_transactions(search_key, order, limit, after)` * `search_key`: [`IndexerSearchKey`](#type-indexersearchkey) @@ -2851,6 +2904,7 @@ Response "id": 2 } ``` + #### Method `get_cells_capacity` * `get_cells_capacity(search_key)` * `search_key`: [`IndexerSearchKey`](#type-indexersearchkey) @@ -2911,7 +2965,7 @@ Response } ``` -### Module Integration_test +### Module `Integration_test` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Integration_test&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/integration_test_rpc_doc.json) RPC for Integration Test. @@ -2999,6 +3053,7 @@ Response "error": null } ``` + #### Method `truncate` * `truncate(target_tip_hash)` * `target_tip_hash`: [`H256`](#type-h256) @@ -3034,6 +3089,7 @@ Response "result": null } ``` + #### Method `generate_block` * `generate_block()` @@ -3066,6 +3122,7 @@ Response "error": null } ``` + #### Method `generate_epochs` * `generate_epochs(num_epochs)` * `num_epochs`: [`Uint64`](#type-uint64) @@ -3121,6 +3178,7 @@ Response "error": null } ``` + #### Method `notify_transaction` * `notify_transaction(transaction)` * `transaction`: [`Transaction`](#type-transaction) @@ -3190,6 +3248,7 @@ Response "error": null } ``` + #### Method `generate_block_with_template` * `generate_block_with_template(block_template)` * `block_template`: [`BlockTemplate`](#type-blocktemplate) @@ -3298,6 +3357,7 @@ Response "error": null } ``` + #### Method `calculate_dao_field` * `calculate_dao_field(block_template)` * `block_template`: [`BlockTemplate`](#type-blocktemplate) @@ -3405,7 +3465,7 @@ Response } ``` -### Module Miner +### Module `Miner` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Miner&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/miner_rpc_doc.json) RPC Module Miner for miners. @@ -3530,6 +3590,7 @@ Response } } ``` + #### Method `submit_block` * `submit_block(work_id, block)` * `work_id`: `string` @@ -3618,7 +3679,7 @@ Response } ``` -### Module Net +### Module `Net` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Net&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/net_rpc_doc.json) RPC Module Net for P2P network. @@ -3685,6 +3746,7 @@ Response } } ``` + #### Method `get_peers` * `get_peers()` @@ -3831,6 +3893,7 @@ Response ] } ``` + #### Method `get_banned_addresses` * `get_banned_addresses()` @@ -3867,6 +3930,7 @@ Response ] } ``` + #### Method `clear_banned_addresses` * `clear_banned_addresses()` @@ -3896,6 +3960,7 @@ Response "result": null } ``` + #### Method `set_ban` * `set_ban(address, command, ban_time, absolute, reason)` * `address`: `string` @@ -3951,6 +4016,7 @@ Response "result": null } ``` + #### Method `sync_state` * `sync_state()` @@ -3989,6 +4055,7 @@ Response } } ``` + #### Method `set_network_active` * `set_network_active(state)` * `state`: `boolean` @@ -4024,6 +4091,7 @@ Response "result": null } ``` + #### Method `add_node` * `add_node(peer_id, address)` * `peer_id`: `string` @@ -4087,6 +4155,7 @@ Response "result": null } ``` + #### Method `remove_node` * `remove_node(peer_id)` * `peer_id`: `string` @@ -4126,6 +4195,7 @@ Response "result": null } ``` + #### Method `ping_peers` * `ping_peers()` @@ -4156,7 +4226,7 @@ Response } ``` -### Module Pool +### Module `Pool` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Pool&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/pool_rpc_doc.json) RPC Module Pool for transaction memory pool. @@ -4252,6 +4322,7 @@ Response "result": "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3" } ``` + #### Method `remove_transaction` * `remove_transaction(tx_hash)` * `tx_hash`: [`H256`](#type-h256) @@ -4291,6 +4362,7 @@ Response "result": true } ``` + #### Method `tx_pool_info` * `tx_pool_info()` @@ -4333,6 +4405,7 @@ Response } } ``` + #### Method `clear_tx_pool` * `clear_tx_pool()` @@ -4362,6 +4435,7 @@ Response "result": null } ``` + #### Method `get_raw_tx_pool` * `get_raw_tx_pool(verbose)` * `verbose`: `boolean` `|` `null` @@ -4408,6 +4482,7 @@ Response } } ``` + #### Method `tx_pool_ready` * `tx_pool_ready()` @@ -4438,7 +4513,7 @@ Response } ``` -### Module Stats +### Module `Stats` - [👉 OpenRPC spec](http://playground.open-rpc.org/?uiSchema[appBar][ui:title]=CKB-Stats&uiSchema[appBar][ui:splitView]=false&uiSchema[appBar][ui:examplesDropdown]=false&uiSchema[appBar][ui:logoUrl]=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/ckb-logo.jpg&schemaUrl=https://raw.githubusercontent.com/chenyukang/ckb-rpc-resources/main/json/stats_rpc_doc.json) RPC Module Stats for getting various statistic data. @@ -4486,6 +4561,7 @@ Response } } ``` + #### Method `get_deployments_info` * `get_deployments_info()` @@ -4694,7 +4770,10 @@ Unsubscribe Response } ``` + + ## RPC Types + ### Type `Alert` An alert is a message about critical problems to be broadcast to all nodes via the p2p network. @@ -6360,6 +6439,7 @@ The uncle block template of the new block for miners. * `required`: `boolean` - Whether miners must include this uncle in the submit block. + ## RPC Errors CKB RPC error codes. @@ -6386,6 +6466,7 @@ codes. Unless otherwise noted, all the errors return optional detailed information as `string` in the error object `data` field. + ### ERROR `CKBInternalError` (-1): CKB internal errors are considered to never happen or only happen when the system resources are exhausted.