diff --git a/Cargo.lock b/Cargo.lock index bba7cba22925f0fea43fb97765e10548195e500d..43f67b8000b2632c513aa931f4bdb84cb0e08126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -729,6 +729,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + [[package]] name = "base16ct" version = "0.2.0" @@ -1100,6 +1106,22 @@ dependencies = [ "rand_chacha", ] +[[package]] +name = "common-multipart-rfc7578" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baee326bc603965b0f26583e1ecd7c111c41b49bd92a344897476a352798869" +dependencies = [ + "bytes", + "futures-core", + "futures-util", + "http", + "mime", + "mime_guess", + "rand", + "thiserror", +] + [[package]] name = "common-path" version = "1.0.0" @@ -1179,6 +1201,15 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -1450,6 +1481,32 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + +[[package]] +name = "data-encoding-macro" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1559b6cba622276d6d63706db152618eeb15b89b3e4041446b05876e352e639" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "332d754c0af53bc87c108fed664d121ecf59207ec4196041f04d6ab9002ad33f" +dependencies = [ + "data-encoding", + "syn 1.0.109", +] + [[package]] name = "der" version = "0.7.8" @@ -1534,6 +1591,15 @@ dependencies = [ "dirs-sys 0.4.1", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -2107,6 +2173,7 @@ dependencies = [ "graphql_client", "hex", "inquire", + "ipfs-api-backend-hyper", "log", "nacl", "parity-scale-codec", @@ -2436,6 +2503,34 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-multipart-rfc7578" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0eb2cf73e96e9925f4bed948e763aa2901c2f1a3a5f713ee41917433ced6671" +dependencies = [ + "bytes", + "common-multipart-rfc7578", + "futures-core", + "http", + "hyper", +] + +[[package]] +name = "hyper-rustls" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +dependencies = [ + "http", + "hyper", + "log", + "rustls 0.20.9", + "rustls-native-certs 0.6.3", + "tokio", + "tokio-rustls 0.23.4", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -2695,6 +2790,49 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b3f7cef34251886990511df1c61443aa928499d598a9473929ab5a90a527304" +[[package]] +name = "ipfs-api-backend-hyper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9d131b408b4caafe1e7c00d410a09ad3eb7e3ab68690cf668e86904b2176b4" +dependencies = [ + "async-trait", + "base64 0.13.1", + "bytes", + "futures", + "http", + "hyper", + "hyper-multipart-rfc7578", + "hyper-rustls 0.23.2", + "ipfs-api-prelude", + "thiserror", +] + +[[package]] +name = "ipfs-api-prelude" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b74065805db266ba2c6edbd670b23c4714824a955628472b2e46cc9f3a869cb" +dependencies = [ + "async-trait", + "bytes", + "cfg-if", + "common-multipart-rfc7578", + "dirs", + "futures", + "http", + "multiaddr", + "multibase", + "serde", + "serde_json", + "serde_urlencoded", + "thiserror", + "tokio", + "tokio-util", + "tracing", + "walkdir", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -2809,7 +2947,7 @@ checksum = "1ccf93fc4a0bfe05d851d37d7c32b7f370fe94336b52a2f0efc5f1981895c2e5" dependencies = [ "async-trait", "hyper", - "hyper-rustls", + "hyper-rustls 0.24.2", "jsonrpsee-core", "jsonrpsee-types", "serde", @@ -3049,6 +3187,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -3076,6 +3224,61 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "multiaddr" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b36f567c7099511fa8612bbbb52dda2419ce0bdbacf31714e3a5ffdb766d3bd" +dependencies = [ + "arrayref", + "byteorder", + "data-encoding", + "log", + "multibase", + "multihash", + "percent-encoding", + "serde", + "static_assertions", + "unsigned-varint", + "url", +] + +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + +[[package]] +name = "multihash" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" +dependencies = [ + "core2", + "multihash-derive", + "unsigned-varint", +] + +[[package]] +name = "multihash-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" +dependencies = [ + "proc-macro-crate 1.1.3", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", + "synstructure", +] + [[package]] name = "nacl" version = "0.5.3" @@ -3487,12 +3690,12 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell", - "toml_edit 0.19.15", + "thiserror", + "toml 0.5.11", ] [[package]] @@ -3716,7 +3919,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls", + "hyper-rustls 0.24.2", "ipnet", "js-sys", "log", @@ -3768,6 +3971,21 @@ dependencies = [ "merlin", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + [[package]] name = "ring" version = "0.17.7" @@ -3777,8 +3995,8 @@ dependencies = [ "cc", "getrandom", "libc", - "spin", - "untrusted", + "spin 0.9.8", + "untrusted 0.9.0", "windows-sys 0.48.0", ] @@ -3891,6 +4109,18 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" +dependencies = [ + "log", + "ring 0.16.20", + "sct", + "webpki", +] + [[package]] name = "rustls" version = "0.21.10" @@ -3974,7 +4204,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ "ring 0.17.7", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -3985,7 +4215,7 @@ checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" dependencies = [ "ring 0.17.7", "rustls-pki-types", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -4090,7 +4320,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a304e1af7cdfbe7a24e08b012721456cc8cecdedadc14b3d10513eada63233c" dependencies = [ "darling 0.14.4", - "proc-macro-crate 1.3.1", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 1.0.109", @@ -4229,7 +4459,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ "ring 0.17.7", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -5085,6 +5315,12 @@ dependencies = [ "sp-debug-derive 14.0.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -5305,6 +5541,18 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5429,6 +5677,17 @@ dependencies = [ "syn 2.0.65", ] +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.9", + "tokio", + "webpki", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -5506,17 +5765,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.2.2", - "toml_datetime", - "winnow", -] - [[package]] name = "toml_edit" version = "0.21.1" @@ -5758,6 +6006,15 @@ dependencies = [ "tinystr", ] +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -5816,6 +6073,18 @@ dependencies = [ "void", ] +[[package]] +name = "unsigned-varint" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -5979,7 +6248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8281d1d660cdf54c76a3efa9ddd0c270cada1383a995db3ccb43d166456c7" dependencies = [ "smallvec", - "spin", + "spin 0.9.8", "wasmi_arena", "wasmi_core", "wasmparser-nostd", @@ -6164,6 +6433,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" +dependencies = [ + "ring 0.17.7", + "untrusted 0.9.0", +] + [[package]] name = "webpki-roots" version = "0.25.4" diff --git a/Cargo.toml b/Cargo.toml index 60d8d98e7921eaae18012fdddf1cb227f8accd42..e1f33e9e2453d628e1e39f68b5c8dd209bd1ba27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,8 @@ inquire = "^0.6.2" directories = "^5.0.1" comfy-table = "^7.1.1" +# ipfs RPC API +ipfs-api-backend-hyper = { version = "0.6", features = ["with-hyper-rustls"] } # crypto scrypt = { version = "^0.11", default-features = false } # for old-style key generation nacl = { version = "^0.5.3" } # for old-style key generation diff --git a/src/commands.rs b/src/commands.rs index 24debbeb2d984716eca3f22a3d20f3d3b5ccd20c..44a2a5b1faf74d20b7ddf9308bb7534acb420d65 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,9 +3,11 @@ pub mod blockchain; pub mod certification; pub mod cesium; pub mod collective; +pub mod commented; pub mod distance; pub mod expire; pub mod identity; +pub mod ipfs; pub mod net_test; pub mod oneshot; pub mod publish; @@ -16,4 +18,3 @@ pub mod sudo; pub mod transfer; pub mod ud; pub mod vault; -pub mod commented; diff --git a/src/commands/ipfs.rs b/src/commands/ipfs.rs new file mode 100644 index 0000000000000000000000000000000000000000..e00b7d536ba22f0d99b8a836197b1a9e4214fbce --- /dev/null +++ b/src/commands/ipfs.rs @@ -0,0 +1,46 @@ +use crate::{Data, GcliError}; +use ipfs_api_backend_hyper::response::{AddResponse, VersionResponse}; +use ipfs_api_backend_hyper::{IpfsApi, IpfsClient}; +use std::io::Cursor; + +/// get version of ipfs node +async fn get_version() -> Result<VersionResponse, ipfs_api_backend_hyper::Error> { + let client = IpfsClient::default(); + client.version().await +} + +/// upload string as text file +async fn upload_string(txt: &str) -> Result<AddResponse, ipfs_api_backend_hyper::Error> { + let client = IpfsClient::default(); + let data = Cursor::new(txt.to_owned()); + client.add(data).await +} + +/// define ipfs subcommands +#[derive(Clone, Default, Debug, clap::Parser)] +pub enum Subcommand { + // Nothing + #[default] + #[clap(hide = true)] + Nothing, + /// Get version of IPFS node + Version, + /// Upload string as IPFS + Upload { txt: String }, +} + +/// handle blockchain commands +pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), GcliError> { + match command { + Subcommand::Nothing => {} + Subcommand::Version => { + let version = get_version().await.map_err(|e| anyhow::anyhow!(e))?; + println!("{:?}", version); + } + Subcommand::Upload { txt } => { + let response = upload_string(&txt).await.map_err(|e| anyhow::anyhow!(e))?; + println!("{:?}", response); + } + } + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index f6571baaf2746611be5f40814d282f865b620956..703b8f7c9e817636b488a568d39126c076ec19e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,6 +142,9 @@ pub enum Subcommand { /// Cesium #[clap(subcommand, hide = true)] Cesium(commands::cesium::Subcommand), + /// IPFS + #[clap(subcommand, hide = true)] + Ipfs(commands::ipfs::Subcommand), /// Publish a new git tag with actual version #[clap(hide = true)] Publish, @@ -181,6 +184,7 @@ async fn main() -> Result<(), GcliError> { Subcommand::Config(subcommand) => conf::handle_command(data, subcommand), Subcommand::Vault(subcommand) => commands::vault::handle_command(data, subcommand), Subcommand::Cesium(subcommand) => commands::cesium::handle_command(data, subcommand).await, + Subcommand::Ipfs(subcommand) => commands::ipfs::handle_command(data, subcommand).await, Subcommand::Publish => commands::publish::handle_command().await, }; if let Err(ref e) = result {