diff --git a/Cargo.lock b/Cargo.lock index 4ca28c04fff34a8ec94befdf139c4d6a05b9b9e0..aaae0a6c878c17e0880a7cc13f00090eb2bd1122 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,7 +106,7 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "getrandom", "once_cell", "version_check", @@ -496,7 +496,7 @@ dependencies = [ "ark-std", "digest 0.10.7", "rand_core 0.6.4", - "sha3 0.10.8", + "sha3", ] [[package]] @@ -520,12 +520,6 @@ dependencies = [ "nodrop", ] -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "arrayvec" version = "0.7.4" @@ -583,7 +577,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f97ab0c5b00a7cdbe5a371b9a782ee7be1316095885c8a4ea1daf490eb0ef65" dependencies = [ "async-lock 3.3.0", - "cfg-if 1.0.0", + "cfg-if", "concurrent-queue", "futures-io", "futures-lite", @@ -637,7 +631,7 @@ dependencies = [ "async-lock 3.3.0", "async-signal", "blocking", - "cfg-if 1.0.0", + "cfg-if", "event-listener 4.0.3", "futures-lite", "rustix 0.38.31", @@ -653,7 +647,7 @@ dependencies = [ "async-io", "async-lock 2.8.0", "atomic-waker", - "cfg-if 1.0.0", + "cfg-if", "futures-core", "futures-io", "rustix 0.38.31", @@ -705,7 +699,7 @@ checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line 0.21.0", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object 0.32.2", @@ -873,17 +867,6 @@ dependencies = [ "constant_time_eq 0.1.5", ] -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "constant_time_eq 0.1.5", -] - [[package]] name = "blake2b_simd" version = "1.0.2" @@ -897,28 +880,26 @@ dependencies = [ [[package]] name = "blake2s_simd" -version = "0.5.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e461a7034e85b211a4acb57ee2e6730b32912b06c08cc242243c39fc21ae6a2" +checksum = "94230421e395b9920d23df13ea5d77a20e1725331f90fbbf6df6040b33f756ae" dependencies = [ "arrayref", - "arrayvec 0.5.2", - "constant_time_eq 0.1.5", + "arrayvec 0.7.4", + "constant_time_eq 0.3.0", ] [[package]] name = "blake3" -version = "0.3.8" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" dependencies = [ "arrayref", - "arrayvec 0.5.2", + "arrayvec 0.7.4", "cc", - "cfg-if 0.1.10", - "constant_time_eq 0.1.5", - "crypto-mac", - "digest 0.9.0", + "cfg-if", + "constant_time_eq 0.3.0", ] [[package]] @@ -927,7 +908,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", "generic-array", ] @@ -940,12 +920,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "blocking" version = "1.5.1" @@ -1016,12 +990,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -1034,7 +1002,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cipher", "cpufeatures", ] @@ -1066,13 +1034,30 @@ dependencies = [ [[package]] name = "cid" -version = "0.7.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6b8976b33648136e969aafa6eb33d58ff0d301fa0b4e8d513db58fd32cd81aa" +checksum = "f6ed9c8b2d17acb8110c46f1da5bf4a696d745e1474a16db0cd2b49cd0249bf2" dependencies = [ + "core2", "multibase", - "multihash 0.14.0", - "unsigned-varint", + "multihash 0.16.3", + "serde", + "serde_bytes", + "unsigned-varint 0.7.2", +] + +[[package]] +name = "cid" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3147d8272e8fa0ccd29ce51194dd98f79ddfb8191ba9e3409884e751798acf3a" +dependencies = [ + "core2", + "multibase", + "multihash 0.19.1", + "serde", + "serde_bytes", + "unsigned-varint 0.8.0", ] [[package]] @@ -1283,7 +1268,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1310,7 +1295,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1443,7 +1428,7 @@ version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", @@ -1541,7 +1526,7 @@ version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "hashbrown 0.14.3", "lock_api", "once_cell", @@ -1877,7 +1862,7 @@ version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -2082,7 +2067,7 @@ version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "878babb0b136e731cc77ec2fd883ff02745ff21e6fb662729953d44923df009c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "parity-scale-codec", "scale-info", ] @@ -2093,7 +2078,7 @@ version = "16.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "parity-scale-codec", "scale-info", "serde", @@ -2231,7 +2216,7 @@ dependencies = [ "anyhow", "bip39", "bs58", - "cid", + "cid 0.11.1", "clap", "comfy-table", "confy", @@ -2242,6 +2227,7 @@ dependencies = [ "hex", "inquire", "ipfs-api-backend-hyper", + "ipld-core", "log", "nacl", "parity-scale-codec", @@ -2249,6 +2235,7 @@ dependencies = [ "rpassword", "scrypt", "serde", + "serde_ipld_dagcbor", "serde_json", "sp-core", "sp-runtime", @@ -2273,7 +2260,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] @@ -2394,6 +2381,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + [[package]] name = "hash-db" version = "0.16.0" @@ -2810,7 +2803,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -2884,7 +2877,7 @@ checksum = "9b74065805db266ba2c6edbd670b23c4714824a955628472b2e46cc9f3a869cb" dependencies = [ "async-trait", "bytes", - "cfg-if 1.0.0", + "cfg-if", "common-multipart-rfc7578", "dirs", "futures", @@ -2901,6 +2894,17 @@ dependencies = [ "walkdir", ] +[[package]] +name = "ipld-core" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ede82a79e134f179f4b29b5fdb1eb92bd1b38c4dfea394c539051150a21b9b" +dependencies = [ + "cid 0.11.1", + "serde", + "serde_bytes", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -3046,7 +3050,7 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "ecdsa", "elliptic-curve", "once_cell", @@ -3307,7 +3311,7 @@ dependencies = [ "percent-encoding", "serde", "static_assertions", - "unsigned-varint", + "unsigned-varint 0.7.2", "url", ] @@ -3324,19 +3328,21 @@ dependencies = [ [[package]] name = "multihash" -version = "0.14.0" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "752a61cd890ff691b4411423d23816d5866dd5621e4d1c5687a53b94b5a979d8" +checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" dependencies = [ - "blake2b_simd 0.5.11", + "blake2b_simd", "blake2s_simd", "blake3", - "digest 0.9.0", - "generic-array", - "multihash-derive 0.7.2", - "sha2 0.9.9", - "sha3 0.9.1", - "unsigned-varint", + "core2", + "digest 0.10.7", + "multihash-derive", + "serde", + "serde-big-array", + "sha2 0.10.8", + "sha3", + "unsigned-varint 0.7.2", ] [[package]] @@ -3346,22 +3352,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" dependencies = [ "core2", - "multihash-derive 0.8.1", - "unsigned-varint", + "multihash-derive", + "unsigned-varint 0.7.2", ] [[package]] -name = "multihash-derive" -version = "0.7.2" +name = "multihash" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99" +checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" dependencies = [ - "proc-macro-crate 1.1.3", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure", + "core2", + "serde", + "unsigned-varint 0.7.2", ] [[package]] @@ -3606,7 +3609,7 @@ version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", "smallvec", @@ -3749,7 +3752,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30054e72317ab98eddd8561db0f6524df3367636884b7b21b703e4b280a84a14" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "concurrent-queue", "pin-project-lite", "rustix 0.38.31", @@ -4432,7 +4435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eca070c12893629e2cc820a9761bedf6ce1dcddc9852984d1dc734b8bd9bd024" dependencies = [ "bitvec", - "cfg-if 1.0.0", + "cfg-if", "derive_more", "parity-scale-codec", "scale-info-derive", @@ -4511,7 +4514,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "772575a524feeb803e5b0fcbc6dd9f367e579488197c94c6e4023aad2305774d" dependencies = [ "ahash 0.8.7", - "cfg-if 1.0.0", + "cfg-if", "hashbrown 0.13.2", ] @@ -4656,6 +4659,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd31f59f6fe2b0c055371bb2f16d7f0aa7d8881676c04a55b1596d1a17cd10a4" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.14" @@ -4676,6 +4688,17 @@ dependencies = [ "syn 2.0.65", ] +[[package]] +name = "serde_ipld_dagcbor" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "950f35fcae42dd9268d9253eb8f846dcef4d66e4e7d56494f38c8eb13e16d87b" +dependencies = [ + "cid 0.8.6", + "half", + "serde", +] + [[package]] name = "serde_json" version = "1.0.117" @@ -4725,7 +4748,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ "block-buffer 0.9.0", - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.9.0", "opaque-debug", @@ -4738,7 +4761,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer 0.9.0", - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.9.0", "opaque-debug", @@ -4750,23 +4773,11 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.10.7", ] -[[package]] -name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "keccak", - "opaque-debug", -] - [[package]] name = "sha3" version = "0.10.8" @@ -4914,7 +4925,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.8", - "sha3 0.10.8", + "sha3", "siphasher", "slab", "smallvec", @@ -5105,11 +5116,11 @@ name = "sp-crypto-hashing" version = "0.1.0" source = "git+https://github.com/duniter/duniter-polkadot-sdk.git?branch=duniter-substrate-v1.11.0#030a7b8fd5ef03e4da466e65ce8fe92e3cff90e4" dependencies = [ - "blake2b_simd 1.0.2", + "blake2b_simd", "byteorder", "digest 0.10.7", "sha2 0.10.8", - "sha3 0.10.8", + "sha3", "twox-hash", ] @@ -5732,7 +5743,7 @@ version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", ] @@ -6065,7 +6076,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "digest 0.10.7", "rand", "static_assertions", @@ -6190,6 +6201,12 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" +[[package]] +name = "unsigned-varint" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" + [[package]] name = "untrusted" version = "0.7.1" @@ -6256,7 +6273,7 @@ dependencies = [ "rand_chacha", "rand_core 0.6.4", "sha2 0.10.8", - "sha3 0.10.8", + "sha3", "thiserror", "zeroize", ] @@ -6292,7 +6309,7 @@ version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -6317,7 +6334,7 @@ version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -6410,7 +6427,7 @@ checksum = "f907fdead3153cb9bfb7a93bbd5b62629472dc06dee83605358c64c52ed3dda9" dependencies = [ "anyhow", "bincode", - "cfg-if 1.0.0", + "cfg-if", "indexmap 1.9.3", "libc", "log", @@ -6433,7 +6450,7 @@ version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3b9daa7c14cd4fa3edbf69de994408d5f4b7b0959ac13fa69d465f6597f810d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -6464,7 +6481,7 @@ dependencies = [ "addr2line 0.19.0", "anyhow", "bincode", - "cfg-if 1.0.0", + "cfg-if", "cpp_demangle", "gimli 0.27.3", "log", @@ -6493,7 +6510,7 @@ version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aecae978b13f7f67efb23bd827373ace4578f2137ec110bbf6a4a7cde4121bbd" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "windows-sys 0.45.0", ] @@ -6506,7 +6523,7 @@ checksum = "658cf6f325232b6760e202e5255d823da5e348fdea827eff0a2a22319000b441" dependencies = [ "anyhow", "cc", - "cfg-if 1.0.0", + "cfg-if", "indexmap 1.9.3", "libc", "log", @@ -6813,7 +6830,7 @@ version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "windows-sys 0.48.0", ] diff --git a/Cargo.toml b/Cargo.toml index 5430a2c9d2d1318c7469e84301ef471dd769956f..21f67610ecc4b112e57adf403c904ba3c022ecff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,9 +46,11 @@ inquire = "^0.6.2" directories = "^5.0.1" comfy-table = "^7.1.1" -# IPFS (RPC API and CID) -ipfs-api-backend-hyper = { version = "0.6", features = ["with-hyper-rustls"] } -cid = "0.7.0" +# IPFS (RPC API, CID, IPLD, dagcbor) +ipfs-api-backend-hyper = { version = "^0.6", features = ["with-hyper-rustls"] } +cid = { version = "^0.11.0", features = ["serde"] } +ipld-core = { version = "^0.4.1", features = ["serde"] } +serde_ipld_dagcbor = "^0.1.0" # 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/account.rs b/src/commands/account.rs index 6241c43ad2f1354992001945ba66c8f130709a23..c399250bd03972537663ed62396e9eb3f2ffb6fc 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -24,6 +24,9 @@ pub enum Subcommand { /// Make transaction comment offchain instead of onchain (requires IPFS) #[clap(short = 'x', long = "offchain")] offchain: bool, + /// Make transaction comment offchain instead of onchain and submit index request to datapod (requires IPFS) + #[clap(short = 'd', long = "datapod")] + datapod: bool, }, /// Transfer the same amount for each space-separated address. /// If an address appears mutiple times, it will get multiple times the same amount @@ -49,6 +52,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE is_ud, comment, offchain, + datapod, } => { if let Some(comment) = comment { if is_ud || allow_death { @@ -56,7 +60,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE "ud or allow death commented transfers are not handled yet".to_string(), )); } - if offchain { + if datapod { + commands::commented::transfer_offchain_datapod(&data, amount, dest, comment) + .await?; + } else if offchain { commands::commented::transfer_offchain(&data, amount, dest, comment).await?; } else { commands::commented::transfer_onchain(&data, amount, dest, comment).await?; diff --git a/src/commands/commented.rs b/src/commands/commented.rs index 062a6d91132c9c932c74dea4d4285d10183a2219..c4bd0b4d2eb37e24dc94f5e7408445094e69e607 100644 --- a/src/commands/commented.rs +++ b/src/commands/commented.rs @@ -1,5 +1,28 @@ use crate::*; use cid::Cid; +use ipfs_api_backend_hyper::{IpfsApi, IpfsClient}; +use serde::{Deserialize, Serialize}; +use std::io::Cursor; +use std::time::{SystemTime, UNIX_EPOCH}; + +/// Index request +#[derive(Debug, Serialize, Deserialize)] +struct IndexRequest { + /// pubkey of the author of the document + pubkey: String, + /// timestamp of the document + time: u64, + /// kind of the document, arbitrary string interpreted by the datapod + kind: String, + /// data coming with the index request + data: Option<Cid>, + /// signature of the following byte payload : + /// ["dd" prefix for 'duniter datapods' | timestamp as u64 bytes | kind bytes | data bytes or 0x00] + sig: Option<String>, +} +const TOPIC: &'static str = "ddd"; +const TRANSACTION_COMMENT: &'static str = + "bafkreiegjt5mrfj2hshuw6koejdfiykq57mzjeprfckxj5zpxxtqj4qzeu"; #[cfg(any(feature = "dev", feature = "gdev"))] // find how to get runtime calls type Call = runtime::runtime_types::gdev_runtime::RuntimeCall; @@ -32,6 +55,46 @@ pub async fn transfer_offchain( .map_err(|e| e.into()) } +/// commented balance transfer, offchain upload to local ipfs node, index request for datapods +pub async fn transfer_offchain_datapod( + data: &Data, + amount: u64, + dest: AccountId, + comment: String, +) -> Result<(), GcliError> { + let response = commands::ipfs::upload_string(&comment) + .await + .map_err(|e| anyhow::anyhow!(e))?; + let cid = Cid::from_str(&response.hash).map_err(|e| anyhow!(e))?; + // serialize index request and upload it to ipfs + let irbytes = serde_ipld_dagcbor::to_vec(&IndexRequest { + pubkey: data.address().to_string(), + time: SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("time goes forward") + .as_secs(), + kind: TRANSACTION_COMMENT.to_string(), + data: Some(cid), + sig: None, + }) + .map_err(|e| anyhow!(e))?; + let response2 = commands::ipfs::upload_dagcbor(&irbytes) + .await + .map_err(|e| anyhow::anyhow!(e))?; + let cid2 = Cid::from_str(&response2.cid.cid_string).map_err(|e| anyhow!(e))?; + // submit index request CID to pubsub + let client = IpfsClient::default(); + let ircid = Cursor::new(format!("{}\n", cid2.to_string())); + client + .pubsub_pub(TOPIC, ircid) + .await + .map_err(|e| anyhow!(e))?; + // once offchain comment indexing is requested, write the comment CID as tx comment + transfer(data, amount, dest, cid.to_bytes().to_vec()) + .await + .map_err(|e| e.into()) +} + /// wrap a transfer call and a remark and submit them async fn transfer( data: &Data, diff --git a/src/commands/ipfs.rs b/src/commands/ipfs.rs index abd4e4b4faac0bf3fab1cf00118e513e1ef71606..58207bca6714025df9a980562f79dde48d70b77a 100644 --- a/src/commands/ipfs.rs +++ b/src/commands/ipfs.rs @@ -1,5 +1,6 @@ use crate::{Data, GcliError}; -use ipfs_api_backend_hyper::response::{AddResponse, VersionResponse}; +use ipfs_api_backend_hyper::request::{DagCodec, DagPut}; +use ipfs_api_backend_hyper::response::{AddResponse, DagPutResponse, VersionResponse}; use ipfs_api_backend_hyper::{IpfsApi, IpfsClient}; use std::io::Cursor; @@ -23,6 +24,21 @@ pub async fn upload_string(txt: &str) -> Result<AddResponse, ipfs_api_backend_hy // client.add(data).await // } +/// upload dag +pub async fn upload_dagcbor(bytes: &[u8]) -> Result<DagPutResponse, ipfs_api_backend_hyper::Error> { + let client = IpfsClient::default(); + let data = Cursor::new(bytes.to_owned()); + client + .dag_put_with_options( + data, + DagPut { + input_codec: Some(DagCodec::Cbor), + ..Default::default() + }, + ) + .await +} + /// define ipfs subcommands #[derive(Clone, Default, Debug, clap::Parser)] pub enum Subcommand {