From 63f0eeecf0db03999d444c179d0b410f1f183ec0 Mon Sep 17 00:00:00 2001 From: Ricky Saechao Date: Mon, 13 May 2024 11:24:32 -0700 Subject: [PATCH] feat: get contract id from mirror node Signed-off-by: Ricky Saechao --- Cargo.lock | 210 +++++++++---------- src/client/mirror/mod.rs | 74 ++++++- src/contract/contract_id.rs | 27 +++ tests/e2e/contract/contract_id_population.rs | 68 ++++++ tests/e2e/contract/mod.rs | 1 + 5 files changed, 269 insertions(+), 111 deletions(-) create mode 100644 tests/e2e/contract/contract_id_population.rs diff --git a/Cargo.lock b/Cargo.lock index 087642af..bcd7b131 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,9 +41,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -104,9 +104,9 @@ checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" [[package]] name = "arc-swap" -version = "1.7.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +checksum = "7b3d0060af21e8d11a926981cc00c6c1541aa91dd64b9f881985c3da1094425f" [[package]] name = "arrayvec" @@ -139,25 +139,25 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] name = "autocfg" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" @@ -213,7 +213,7 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper 1.0.0", + "sync_wrapper 1.0.1", "tokio", "tower", "tower-layer", @@ -272,9 +272,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -317,9 +317,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "bitvec" @@ -353,9 +353,9 @@ dependencies = [ [[package]] name = "borsh" -version = "1.4.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0901fc8eb0aca4c83be0106d6f2db17d86a08dfc2c25f0e84464bf381158add6" +checksum = "f58b559fd6448c6e2fd0adb5720cd98a2506594cafa4737ff98c396f3e82f667" dependencies = [ "borsh-derive", "cfg_aliases", @@ -363,23 +363,23 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.4.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51670c3aa053938b0ee3bd67c3817e471e626151131b934038e83c5bf8de48f5" +checksum = "7aadb5b6ccbd078890f6d7003694e33816e6b784358f18e15e7e6d9f065a57cd" dependencies = [ "once_cell", "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", "syn_derive", ] [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytecheck" @@ -405,9 +405,9 @@ dependencies = [ [[package]] name = "bytes" -version = "1.6.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cbc" @@ -448,9 +448,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" dependencies = [ "clap_builder", "clap_derive", @@ -470,14 +470,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -570,14 +570,14 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] name = "der" -version = "0.7.9" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", "zeroize", @@ -612,7 +612,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -740,9 +740,9 @@ dependencies = [ [[package]] name = "expect-test" -version = "1.5.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e0be0a561335815e06dab7c62e50353134c796e7a6155402a64bcff66b6a5e0" +checksum = "30d9eafeadd538e68fb28016364c9732d78e420b9ff8853fa5e4058861e9f8d3" dependencies = [ "dissimilar", "once_cell", @@ -750,9 +750,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "ff" @@ -766,9 +766,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" [[package]] name = "fixedbitset" @@ -808,9 +808,9 @@ dependencies = [ [[package]] name = "fraction" -version = "0.15.2" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fac69bd85b6b19696fae3aa269c3e03c2d12e19a87f0e67f01bc1518cf0025e0" +checksum = "b486ab61634f05b11b591c38c71fb25139cb55e22be4fb6ecf649cc3736c074a" dependencies = [ "num", ] @@ -901,9 +901,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.26" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" dependencies = [ "bytes", "fnv", @@ -911,7 +911,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.2.6", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -930,7 +930,7 @@ dependencies = [ "futures-sink", "futures-util", "http 1.1.0", - "indexmap 2.2.6", + "indexmap 2.2.5", "slab", "tokio", "tokio-util", @@ -954,9 +954,9 @@ checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" -version = "0.5.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hedera" @@ -1139,7 +1139,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.26", + "h2 0.3.24", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -1244,9 +1244,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -1288,9 +1288,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" @@ -1371,9 +1371,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -1389,7 +1389,7 @@ checksum = "f09fa787e06d071d09c2964b065eb7cb1b842a7af5382fc4c9142089f8383f08" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -1557,7 +1557,7 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.4.2", "cfg-if", "foreign-types", "libc", @@ -1574,7 +1574,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -1651,7 +1651,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.2.6", + "indexmap 2.2.5", ] [[package]] @@ -1671,14 +1671,14 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1721,9 +1721,9 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platforms" -version = "3.4.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" +checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" [[package]] name = "powerfmt" @@ -1744,7 +1744,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" dependencies = [ "proc-macro2", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -1815,7 +1815,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.58", + "syn 2.0.52", "tempfile", ] @@ -1829,7 +1829,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -1917,9 +1917,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", @@ -1940,9 +1940,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rend" @@ -1955,9 +1955,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e6cc1e89e689536eb5aeede61520e874df5a4707df811cd5da4aa5fbb2aae19" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ "base64 0.22.0", "bytes", @@ -2061,9 +2061,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.35.0" +version = "1.34.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +checksum = "b39449a79f45e8da28c57c341891b69a183044b29518bb8f86dbac9df60bb7df" dependencies = [ "arrayvec", "borsh", @@ -2098,11 +2098,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.4.2", "errno", "libc", "linux-raw-sys", @@ -2232,9 +2232,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -2263,14 +2263,14 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -2347,9 +2347,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.2" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" @@ -2379,9 +2379,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "subtle" @@ -2402,9 +2402,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -2420,7 +2420,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -2431,9 +2431,9 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "sync_wrapper" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384595c11a4e2969895cad5a8c4029115f5ab956a9e5ef4de79d11a426e5f20c" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" [[package]] name = "system-configuration" @@ -2491,7 +2491,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -2539,9 +2539,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", @@ -2573,7 +2573,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -2599,9 +2599,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", "pin-project-lite", @@ -2634,7 +2634,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.2.5", "toml_datetime", "winnow", ] @@ -2650,7 +2650,7 @@ dependencies = [ "axum 0.6.20", "base64 0.21.7", "bytes", - "h2 0.3.26", + "h2 0.3.24", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", @@ -2680,7 +2680,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -2735,7 +2735,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", ] [[package]] @@ -2824,9 +2824,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.8.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" [[package]] name = "vcpkg" @@ -2876,7 +2876,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", "wasm-bindgen-shared", ] @@ -2910,7 +2910,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/src/client/mirror/mod.rs b/src/client/mirror/mod.rs index 500eb5ba..21ff51a5 100644 --- a/src/client/mirror/mod.rs +++ b/src/client/mirror/mod.rs @@ -1,9 +1,14 @@ +use std::str::FromStr; + +use hyper::Uri; +use reqwest::Client as ReqwestClient; use serde_json::Value; use triomphe::Arc; use crate::{ Client, Error, + EvmAddress, LedgerId, }; @@ -47,7 +52,6 @@ impl MirrorNodeGateway { } } - // Gets called in MirrorNodeGateway async fn get_account_info(&self, id_or_address: String) -> Value { let api_url = MirrorNodeRouter::build_api_url( self.inner.load().mirror_node_url.clone(), @@ -61,9 +65,39 @@ impl MirrorNodeGateway { info } - // todo: Return Result instead of unwrapping + async fn get_contract_info(&self, id_or_address: String) -> Value { + let api_url = MirrorNodeRouter::build_api_url( + self.inner.load().mirror_node_url.clone(), + MirrorRoutes::ContractsRoute, + id_or_address, + ); + + let response_body = self.query_from_mirror_node(api_url).await; + + let info = serde_json::from_str(&response_body).unwrap(); + info + } + + async fn get_account_tokens(&self, id_or_address: String) -> Value { + let api_url = MirrorNodeRouter::build_api_url( + self.inner.load().mirror_node_url.clone(), + MirrorRoutes::AccountTokensRoute, + id_or_address, + ); + + let response_body = self.query_from_mirror_node(api_url).await; + + let info = serde_json::from_str(&response_body).unwrap(); + info + } + async fn query_from_mirror_node(&self, api_url: String) -> String { - reqwest::get(api_url).await.unwrap().text().await.unwrap() + let client = ReqwestClient::new(); + println!("url: {api_url}"); + let response = client.get(&api_url).send().await.unwrap(); + println!("response: {response:?}"); + let body = response.text().await.unwrap(); + body } } @@ -106,7 +140,7 @@ impl MirrorNodeRouter { if ledger_id.is_some() { return Ok(format!("https://{}", address[0])); } else { - return Ok(format!("http://{}:{}", address[0], LOCAL_NODE_PORT)); + return Ok(format!("{}:{}", address[0], LOCAL_NODE_PORT)); } } @@ -139,7 +173,35 @@ impl MirrorNodeService { } } - // async fn get_account_evm_adress(&self, num: u64) -> EvmAddress { + async fn get_account_evm_adress(&self, num: u64) -> crate::Result { + let expecting = || Error::basic_parse(format!("Could not parse data")); + + let account_info = self.mirror_node_gateway.get_account_info(num.to_string()).await; + + let num = account_info.get("evm_address").map(|it| it.as_str().unwrap()).unwrap(); + + if let Some(index) = num.rfind('.') { + let substring = &num[index + 1..]; + EvmAddress::from_str(substring) + } else { + crate::Result::Err(expecting()) + } + } + + pub async fn get_contract_num(&self, evm_address: String) -> crate::Result { + let expecting = || Error::basic_parse(format!("Could not parse data")); + + let contract_info = self.mirror_node_gateway.get_contract_info(evm_address).await; + + println!("contract info = {contract_info}"); - // } + let num = contract_info.get("contract_id").map(|it| it.as_str().unwrap()).unwrap(); + + if let Some(index) = num.rfind('.') { + let substring = &num[index + 1..]; + substring.parse::().map_err(|e| crate::Error::BasicParse(Box::new(e))) + } else { + crate::Result::Err(expecting()) + } + } } diff --git a/src/contract/contract_id.rs b/src/contract/contract_id.rs index ea6ee58e..155ce3fa 100644 --- a/src/contract/contract_id.rs +++ b/src/contract/contract_id.rs @@ -28,6 +28,10 @@ use std::str::FromStr; use hedera_proto::services; +use crate::client::{ + MirrorNodeGateway, + MirrorNodeService, +}; use crate::entity_id::{ Checksum, PartialEntityId, @@ -39,6 +43,7 @@ use crate::{ Client, EntityId, Error, + EvmAddress, FromProtobuf, ToProtobuf, }; @@ -143,6 +148,28 @@ impl ContractId { } } + /// Query contract id from Mirror Node. + pub async fn populate_contract_num(&self, client: &Client) -> crate::Result { + let mirror_node_gateway = MirrorNodeGateway::for_client(client.to_owned()); + let mirror_node_service = MirrorNodeService::new(mirror_node_gateway); + + match self.evm_address { + Some(addr) => { + let evm_address = EvmAddress::from_ref(&addr); + let contract_num = + mirror_node_service.get_contract_num(evm_address.to_string()).await?; + Ok(ContractId { + shard: self.shard, + realm: self.realm, + num: contract_num, + evm_address: self.evm_address, + checksum: self.checksum, + }) + } + None => todo!(), + } + } + /// Validates `self.checksum` (if it exists) for `client`. /// /// # Errors diff --git a/tests/e2e/contract/contract_id_population.rs b/tests/e2e/contract/contract_id_population.rs new file mode 100644 index 00000000..bbfa68d3 --- /dev/null +++ b/tests/e2e/contract/contract_id_population.rs @@ -0,0 +1,68 @@ +use hedera::{ + AccountId, + ContractCreateTransaction, + ContractFunctionParameters, + ContractId, + ContractInfoQuery, + FileCreateTransaction, + Hbar, + PrivateKey, + TransactionReceiptQuery, + TransferTransaction, +}; + +use crate::common::{ + setup_nonfree, + TestEnvironment, +}; +use crate::file; + +const CONTRACT_BYTE_CODE: &str = "608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101cb806100606000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b51461004b578063cfae321714610062575b600080fd5b34801561005757600080fd5b506100606100f2565b005b34801561006e57600080fd5b50610077610162565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b757808201518184015260208101905061009c565b50505050905090810190601f1680156100e45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610160573373ffffffffffffffffffffffffffffffffffffffff16ff5b565b60606040805190810160405280600d81526020017f48656c6c6f2c20776f726c64210000000000000000000000000000000000000081525090509056fea165627a7a72305820ae96fb3af7cde9c0abfe365272441894ab717f816f07f41f07b1cbede54e256e0029"; + +#[tokio::test] +async fn can_populate_contract_id_num() -> anyhow::Result<()> { + let Some(TestEnvironment { config, client }) = setup_nonfree() else { + return Ok(()); + }; + + let Some(op) = &config.operator else { + log::debug!("skipping test due to missing operator"); + return Ok(()); + }; + + let receipt = FileCreateTransaction::new() + .keys([client.get_operator_public_key().unwrap()]) + .contents(CONTRACT_BYTE_CODE) + .execute(&client) + .await? + .validate_status(true) + .get_receipt(&client) + .await?; + + let file_id = receipt.file_id.unwrap(); + + let receipt = ContractCreateTransaction::new() + .admin_key(op.private_key.public_key()) + .gas(100000) + .constructor_parameters( + ContractFunctionParameters::new().add_string("Hello from Hedera.").to_bytes(None), + ) + .bytecode_file_id(file_id) + .contract_memo("[e2e::can_populate_contract_id_num") + .execute(&client) + .await? + .validate_status(true) + .get_receipt(&client) + .await?; + + let contract_id = receipt.contract_id.unwrap(); + + let info = ContractInfoQuery::new().contract_id(contract_id).execute(&client).await?; + + let id_mirror = ContractId::from_evm_address(0, 0, &info.contract_account_id).unwrap(); + + let new_contract_id = id_mirror.populate_contract_num(&client).await?; + + assert_eq!(contract_id, new_contract_id); + Ok(()) +} diff --git a/tests/e2e/contract/mod.rs b/tests/e2e/contract/mod.rs index 20261d73..d29a8e1c 100644 --- a/tests/e2e/contract/mod.rs +++ b/tests/e2e/contract/mod.rs @@ -7,6 +7,7 @@ use hedera::{ }; mod bytecode; +mod contract_id_population; mod create; mod create_flow; mod delete;