From 21301e2bf1e8efdc493907807b30318787e2d02d Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 3 Sep 2024 22:46:02 +0200 Subject: [PATCH] receiving now possible --- Cargo.lock | 805 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 + src/jsonrpc.rs | 396 ++++++++++++++++++++++++ src/main.rs | 39 ++- src/recsend.rs | 60 ++++ 5 files changed, 1306 insertions(+), 2 deletions(-) create mode 100644 src/jsonrpc.rs create mode 100644 src/recsend.rs diff --git a/Cargo.lock b/Cargo.lock index f58c354..638fc3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,811 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async-trait" +version = "0.1.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "color-eyre" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[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.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "jsonrpsee" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ec465b607a36dc5dd45d48b7689bc83f679f66a3ac6b6b21cc787a11e0f8685" +dependencies = [ + "jsonrpsee-core", + "jsonrpsee-proc-macros", + "jsonrpsee-types", + "tracing", +] + +[[package]] +name = "jsonrpsee-core" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e942c55635fbf5dc421938b8558a8141c7e773720640f4f1dbe1f4164ca4e221" +dependencies = [ + "async-trait", + "futures-timer", + "futures-util", + "jsonrpsee-types", + "pin-project", + "rustc-hash", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tracing", +] + +[[package]] +name = "jsonrpsee-proc-macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b07a2daf52077ab1b197aea69a5c990c060143835bf04c77070e98903791715" +dependencies = [ + "heck", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "jsonrpsee-types" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b67d6e008164f027afbc2e7bb79662650158d26df200040282d2aa1cbb093b" +dependencies = [ + "http", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.209" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + [[package]] name = "signal-to-blog" version = "0.1.0" +dependencies = [ + "color-eyre", + "jsonrpsee", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tokio-util", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 8ca375e..eecd201 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,11 @@ version = "0.1.0" edition = "2021" [dependencies] +color-eyre = "0.6.3" +jsonrpsee = { version = "0.24.3", features = ["macros", "async-client"] } +serde = { version = "1.0.209", features = ["derive"] } +serde_json = "1.0.127" +thiserror = "1.0.63" +tokio = { version = "1.40.0", features = ["full"] } +tokio-stream = "0.1.15" +tokio-util = { version = "0.7.11", features = ["codec"] } diff --git a/src/jsonrpc.rs b/src/jsonrpc.rs new file mode 100644 index 0000000..c10a6d0 --- /dev/null +++ b/src/jsonrpc.rs @@ -0,0 +1,396 @@ +use jsonrpsee::proc_macros::rpc; +use serde::Deserialize; +use serde_json::Value; + +#[rpc(client)] +pub trait Rpc { + #[method(name = "addDevice", param_kind = map)] + async fn add_device( + &self, + account: Option, + uri: String, + ) -> Result; + + #[method(name = "addStickerPack", param_kind = map)] + async fn add_sticker_pack( + &self, + account: Option, + uri: String, + ) -> Result; + + #[method(name = "block", param_kind = map)] + fn block( + &self, + account: Option, + recipients: Vec, + #[allow(non_snake_case)] groupIds: Vec, + ) -> Result; + + #[method(name = "deleteLocalAccountData", param_kind = map)] + fn delete_local_account_data( + &self, + account: Option, + #[allow(non_snake_case)] ignoreRegistered: Option, + ) -> Result; + + #[method(name = "getAttachment", param_kind = map)] + fn get_attachment( + &self, + account: Option, + id: String, + recipient: Option, + #[allow(non_snake_case)] groupId: Option, + ) -> Result; + + #[method(name = "getAvatar", param_kind = map)] + fn get_avatar( + &self, + account: Option, + contact: Option, + profile: Option, + #[allow(non_snake_case)] groupId: Option, + ) -> Result; + + #[method(name = "getSticker", param_kind = map)] + fn get_sticker( + &self, + account: Option, + #[allow(non_snake_case)] packId: String, + #[allow(non_snake_case)] stickerId: u32, + ) -> Result; + + #[method(name = "getUserStatus", param_kind = map)] + fn get_user_status( + &self, + account: Option, + recipients: Vec, + ) -> Result; + + #[method(name = "joinGroup", param_kind = map)] + fn join_group(&self, account: Option, uri: String) -> Result; + + #[allow(non_snake_case)] + #[method(name = "finishChangeNumber", param_kind = map)] + fn finish_change_number( + &self, + account: Option, + number: String, + verificationCode: String, + pin: Option, + ) -> Result; + + #[method(name = "finishLink", param_kind = map)] + fn finish_link( + &self, + #[allow(non_snake_case)] deviceLinkUri: String, + #[allow(non_snake_case)] deviceName: String, + ) -> Result; + + #[method(name = "listAccounts", param_kind = map)] + fn list_accounts(&self) -> Result; + + #[method(name = "listContacts", param_kind = map)] + fn list_contacts( + &self, + account: Option, + recipients: Vec, + #[allow(non_snake_case)] allRecipients: bool, + blocked: Option, + name: Option, + ) -> Result; + + #[method(name = "listDevices", param_kind = map)] + fn list_devices(&self, account: Option) -> Result; + + #[method(name = "listGroups", param_kind = map)] + fn list_groups( + &self, + account: Option, + #[allow(non_snake_case)] groupIds: Vec, + ) -> Result; + + #[method(name = "listIdentities", param_kind = map)] + fn list_identities( + &self, + account: Option, + number: Option, + ) -> Result; + + #[method(name = "listStickerPacks", param_kind = map)] + fn list_sticker_packs(&self, account: Option) -> Result; + + #[method(name = "quitGroup", param_kind = map)] + fn quit_group( + &self, + account: Option, + #[allow(non_snake_case)] groupId: String, + delete: bool, + admins: Vec, + ) -> Result; + + #[method(name = "register", param_kind = map)] + fn register( + &self, + account: Option, + voice: bool, + captcha: Option, + ) -> Result; + + #[method(name = "removeContact", param_kind = map)] + fn remove_contact( + &self, + account: Option, + recipient: String, + forget: bool, + hide: bool, + ) -> Result; + + #[method(name = "removeDevice", param_kind = map)] + fn remove_device( + &self, + account: Option, + #[allow(non_snake_case)] deviceId: u32, + ) -> Result; + + #[method(name = "removePin", param_kind = map)] + fn remove_pin(&self, account: Option) -> Result; + + #[method(name = "remoteDelete", param_kind = map)] + fn remote_delete( + &self, + account: Option, + #[allow(non_snake_case)] targetTimestamp: u64, + recipients: Vec, + #[allow(non_snake_case)] groupIds: Vec, + #[allow(non_snake_case)] noteToSelf: bool, + ) -> Result; + + #[allow(non_snake_case)] + #[method(name = "send", param_kind = map)] + fn send( + &self, + account: Option, + recipients: Vec, + groupIds: Vec, + noteToSelf: bool, + endSession: bool, + message: String, + attachments: Vec, + mentions: Vec, + textStyle: Vec, + quoteTimestamp: Option, + quoteAuthor: Option, + quoteMessage: Option, + quoteMention: Vec, + quoteTextStyle: Vec, + quoteAttachment: Vec, + preview_url: Option, + preview_title: Option, + preview_description: Option, + preview_image: Option, + sticker: Option, + storyTimestamp: Option, + storyAuthor: Option, + editTimestamp: Option, + ) -> Result; + + #[method(name = "sendContacts", param_kind = map)] + fn send_contacts(&self, account: Option) -> Result; + + #[method(name = "sendPaymentNotification", param_kind = map)] + fn send_payment_notification( + &self, + account: Option, + recipient: String, + receipt: String, + note: String, + ) -> Result; + + #[method(name = "sendReaction", param_kind = map)] + fn send_reaction( + &self, + account: Option, + recipients: Vec, + #[allow(non_snake_case)] groupIds: Vec, + #[allow(non_snake_case)] noteToSelf: bool, + emoji: String, + #[allow(non_snake_case)] targetAuthor: String, + #[allow(non_snake_case)] targetTimestamp: u64, + remove: bool, + story: bool, + ) -> Result; + + #[method(name = "sendReceipt", param_kind = map)] + fn send_receipt( + &self, + account: Option, + recipient: String, + #[allow(non_snake_case)] targetTimestamps: Vec, + r#type: String, + ) -> Result; + + #[method(name = "sendSyncRequest", param_kind = map)] + fn send_sync_request(&self, account: Option) -> Result; + + #[method(name = "sendTyping", param_kind = map)] + fn send_typing( + &self, + account: Option, + recipients: Vec, + #[allow(non_snake_case)] groupIds: Vec, + stop: bool, + ) -> Result; + + #[method(name = "sendMessageRequestResponse", param_kind = map)] + fn send_message_request_response( + &self, + account: Option, + recipients: Vec, + #[allow(non_snake_case)] groupIds: Vec, + r#type: String, + ) -> Result; + + #[method(name = "setPin", param_kind = map)] + fn set_pin(&self, account: Option, pin: String) -> Result; + + #[method(name = "submitRateLimitChallenge", param_kind = map)] + fn submit_rate_limit_challenge( + &self, + account: Option, + challenge: String, + captcha: String, + ) -> Result; + + #[method(name = "startChangeNumber", param_kind = map)] + fn start_change_number( + &self, + account: Option, + number: String, + voice: bool, + captcha: Option, + ) -> Result; + + #[method(name = "startLink", param_kind = map)] + fn start_link(&self, account: Option) -> Result; + + #[method(name = "trust", param_kind = map)] + fn trust( + &self, + account: Option, + recipient: String, + #[allow(non_snake_case)] trustAllKnownKeys: bool, + #[allow(non_snake_case)] verifiedSafetyNumber: Option, + ) -> Result; + + #[method(name = "unblock", param_kind = map)] + fn unblock( + &self, + account: Option, + recipients: Vec, + #[allow(non_snake_case)] groupIds: Vec, + ) -> Result; + + #[method(name = "unregister", param_kind = map)] + fn unregister( + &self, + account: Option, + #[allow(non_snake_case)] deleteAccount: bool, + ) -> Result; + + #[allow(non_snake_case)] + #[method(name = "updateAccount", param_kind = map)] + fn update_account( + &self, + account: Option, + deviceName: Option, + unrestrictedUnidentifiedSender: Option, + discoverableByNumber: Option, + numberSharing: Option, + ) -> Result; + + #[method(name = "updateConfiguration", param_kind = map)] + fn update_configuration( + &self, + account: Option, + #[allow(non_snake_case)] readReceipts: Option, + #[allow(non_snake_case)] unidentifiedDeliveryIndicators: Option, + #[allow(non_snake_case)] typingIndicators: Option, + #[allow(non_snake_case)] linkPreviews: Option, + ) -> Result; + + #[method(name = "updateContact", param_kind = map)] + fn update_contact( + &self, + account: Option, + recipient: String, + name: Option, + expiration: Option, + ) -> Result; + + #[method(name = "updateGroup", param_kind = map)] + fn update_group( + &self, + account: Option, + #[allow(non_snake_case)] groupId: Option, + name: Option, + description: Option, + avatar: Option, + member: Vec, + #[allow(non_snake_case)] removeMember: Vec, + admin: Vec, + #[allow(non_snake_case)] removeAdmin: Vec, + ban: Vec, + unban: Vec, + #[allow(non_snake_case)] resetLink: bool, + #[allow(non_snake_case)] link: Option, + #[allow(non_snake_case)] setPermissionAddMember: Option, + #[allow(non_snake_case)] setPermissionEditDetails: Option, + #[allow(non_snake_case)] setPermissionSendMessages: Option, + expiration: Option, + ) -> Result; + + #[method(name = "updateProfile", param_kind = map)] + fn update_profile( + &self, + account: Option, + #[allow(non_snake_case)] givenName: Option, + #[allow(non_snake_case)] familyName: Option, + about: Option, + #[allow(non_snake_case)] aboutEmoji: Option, + #[allow(non_snake_case)] mobileCoinAddress: Option, + avatar: Option, + #[allow(non_snake_case)] removeAvatar: bool, + ) -> Result; + + #[method(name = "uploadStickerPack", param_kind = map)] + fn upload_sticker_pack( + &self, + account: Option, + path: String, + ) -> Result; + + #[method(name = "verify", param_kind = map)] + fn verify( + &self, + account: Option, + #[allow(non_snake_case)] verificationCode: String, + pin: Option, + ) -> Result; + + #[subscription( + name = "subscribeReceive" => "receive", + unsubscribe = "unsubscribeReceive", + item = Value, + param_kind = map + )] + async fn subscribe_receive(&self, account: Option) -> SubscriptionResult; + + #[method(name = "version")] + fn version(&self) -> Result; +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct JsonLink { + pub device_link_uri: String, +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..faf39ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,38 @@ -fn main() { - println!("Hello, world!"); +use std::process::Stdio; + +use color_eyre::eyre::Result; +use jsonrpsee::async_client::ClientBuilder; +use tokio::process::Command; +use tokio_util::codec::{FramedRead, LinesCodec}; + +use crate::jsonrpc::RpcClient; +mod jsonrpc; +use crate::recsend::{Receiver, Sender}; +mod recsend; + +const COMMAND_PATH: &str = "signal-cli"; + +#[tokio::main] +async fn main() -> Result<()> { + let mut cmd = Command::new(COMMAND_PATH) + .arg("jsonRpc") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn()?; + let sender = Sender { + inner: cmd.stdin.take().unwrap(), + }; + let receiver = Receiver { + inner: FramedRead::new(cmd.stdout.take().unwrap(), LinesCodec::new()), + }; + + let client = ClientBuilder::default().build_with_tokio(sender, receiver); + let mut stream = client.subscribe_receive(None).await?; + { + let v = stream.next().await.unwrap()?; + println!("{v}"); + } + stream.unsubscribe().await?; + + Ok(()) } diff --git a/src/recsend.rs b/src/recsend.rs new file mode 100644 index 0000000..a3b486b --- /dev/null +++ b/src/recsend.rs @@ -0,0 +1,60 @@ +use thiserror::Error; +use tokio::{ + io::{AsyncRead, AsyncWriteExt}, + process::ChildStdin, +}; +use tokio_stream::StreamExt; + +use jsonrpsee::core::{ + async_trait, + client::{ReceivedMessage, TransportReceiverT, TransportSenderT}, +}; +use tokio_util::codec::{FramedRead, LinesCodec}; + +#[derive(Debug, Error)] +pub enum Errors { + #[error("Other: {0}")] + Other(String), + #[error("Closed")] + Closed, +} + +pub struct Sender { + pub inner: ChildStdin, +} + +#[async_trait] +impl TransportSenderT for Sender { + type Error = Errors; + + async fn send(&mut self, body: String) -> Result<(), Errors> { + let body = body + "\n"; + self.inner + .write_all(&body.as_bytes()) + .await + .map_err(|e| Errors::Other(format!("{:?}", e)))?; + Ok(()) + } + + async fn close(&mut self) -> Result<(), Errors> { + Ok(()) + } +} + +pub struct Receiver { + pub inner: FramedRead, +} + +#[async_trait] +impl TransportReceiverT for Receiver { + type Error = Errors; + + async fn receive(&mut self) -> Result { + let dbg = self.inner.next().await; + match dbg { + None => Err(Errors::Closed), + Some(Ok(msg)) => Ok(ReceivedMessage::Text(msg)), + Some(Err(e)) => Err(Errors::Other(format!("{:?}", e))), + } + } +}