From 10c6738b705e79170d7ac4ba18a1571c4c73e476 Mon Sep 17 00:00:00 2001 From: IgorKoval Date: Sun, 28 Jul 2024 12:47:31 +0300 Subject: [PATCH 1/2] upd deps, cargo clippy and fmt --- Cargo.lock | 269 ++++++++++++++++++++++++++++++++---------------- Cargo.toml | 10 +- build.rs | 5 +- src/abi.rs | 9 +- src/keyman.rs | 5 +- src/main.rs | 159 ++++++++++++++-------------- src/printer.rs | 110 +++++++++++--------- src/program.rs | 37 +++++-- src/testcall.rs | 252 +++++++++++++++++++++++++-------------------- 9 files changed, 513 insertions(+), 343 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bf422a0..f35ed954 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,9 +69,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -84,33 +84,33 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys", @@ -124,9 +124,9 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arrayref" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" [[package]] name = "arrayvec" @@ -136,13 +136,14 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "assert_cmd" -version = "2.0.14" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8" +checksum = "dc1835b7f27878de8525dc71410b5a31cdcc5f230aed5ba5df968e09c201b23d" dependencies = [ "anstyle", "bstr", "doc-comment", + "libc", "predicates", "predicates-core", "predicates-tree", @@ -206,9 +207,9 @@ dependencies = [ [[package]] name = "blst" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62dc83a094a71d43eeadd254b1ec2d24cb6a0bb6cadce00df51f0db594711a32" +checksum = "4378725facc195f1a538864863f6de233b500a8862747e7f165078a419d5e874" dependencies = [ "cc", "glob", @@ -218,9 +219,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.9.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", "regex-automata", @@ -241,9 +242,14 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.1.5" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +checksum = "68064e60dbf1f17005c2fde4d07c16d8baa506fd7ffed8ccab702d93617975c7" +dependencies = [ + "jobserver", + "libc", + "shlex", +] [[package]] name = "cfg-if" @@ -291,9 +297,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.9" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -301,9 +307,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.9" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -313,9 +319,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.8" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck", "proc-macro2", @@ -325,15 +331,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "const-oid" @@ -349,15 +355,15 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" dependencies = [ "libc", ] @@ -464,6 +470,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" +[[package]] +name = "diffy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c27ec7cef89a63c063e06570bb861b7d35e406d6885551b346d77c459b34d3db" +dependencies = [ + "ansi_term", +] + [[package]] name = "digest" version = "0.10.7" @@ -524,8 +539,8 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "ever_abi" -version = "2.6.4" -source = "git+https://github.com/everx-labs/ever-abi.git?tag=2.6.4#950384b4e7cb82bcb9d63fbda0ee452e0f3b3bad" +version = "2.7.2" +source = "git+https://github.com/everx-labs/ever-abi.git?tag=2.7.2#70f946130a68db322fa7fe735c77e5998c4fefb4" dependencies = [ "anyhow", "byteorder", @@ -542,11 +557,11 @@ dependencies = [ [[package]] name = "ever_assembler" -version = "1.6.6" -source = "git+https://github.com/everx-labs/ever-assembler.git?tag=1.6.6#82db4cd600ee94cc2410c0f62366578fc4de572a" +version = "1.6.14" +source = "git+https://github.com/everx-labs/ever-assembler.git?tag=1.6.14#0569ad4c246813f3b3f2db27b427c67afd23e8e9" dependencies = [ "anyhow", - "clap 4.5.9", + "clap 4.5.16", "ever_block", "ever_vm", "hex 0.4.3", @@ -560,8 +575,8 @@ dependencies = [ [[package]] name = "ever_block" -version = "1.11.3" -source = "git+https://github.com/everx-labs/ever-block.git?tag=1.11.3#d56c79c85f273522a1d74525710c11c7a4c56790" +version = "1.11.11" +source = "git+https://github.com/everx-labs/ever-block.git?tag=1.11.11#5d617e2f0a8f7ec2b3e0aab9167280260a5ad7f2" dependencies = [ "aes-ctr", "anyhow", @@ -590,17 +605,20 @@ dependencies = [ [[package]] name = "ever_vm" -version = "2.2.4" -source = "git+https://github.com/everx-labs/ever-vm.git?tag=2.2.4#5f5eae27f11065ad0acc95f0ad94777cb6061bef" +version = "2.2.12" +source = "git+https://github.com/everx-labs/ever-vm.git?tag=2.2.12#ebd07bab74de939cfc71b1f56aa314cb58695318" dependencies = [ "anyhow", + "diffy", "ever_block", "hex 0.4.3", "lazy_static", "log", "num", "num-traits", + "similar", "thiserror", + "zstd", ] [[package]] @@ -716,9 +734,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" @@ -726,11 +744,20 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -743,9 +770,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.156" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a" [[package]] name = "lockfree" @@ -895,17 +922,26 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "predicates" -version = "3.1.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" dependencies = [ "anstyle", "difflib", @@ -917,15 +953,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" [[package]] name = "predicates-tree" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" dependencies = [ "predicates-core", "termtree", @@ -1018,9 +1054,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1080,18 +1116,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", @@ -1100,11 +1136,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1120,6 +1157,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -1131,9 +1174,12 @@ dependencies = [ [[package]] name = "similar" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" +dependencies = [ + "bstr", +] [[package]] name = "simplelog" @@ -1182,9 +1228,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.71" +version = "2.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" dependencies = [ "proc-macro2", "quote", @@ -1219,18 +1265,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -1248,7 +1294,7 @@ dependencies = [ [[package]] name = "tvm_linker" -version = "0.21.5" +version = "0.21.6" dependencies = [ "anyhow", "assert_cmd", @@ -1308,9 +1354,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wait-timeout" @@ -1335,19 +1381,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -1360,9 +1407,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1370,9 +1417,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -1383,9 +1430,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "winapi" @@ -1503,6 +1550,27 @@ dependencies = [ "zeroize", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zeroize" version = "1.8.1" @@ -1522,3 +1590,32 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 38ff6e29..80f703c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license-file = 'LICENSE.md' name = 'tvm_linker' readme = 'README.md' repository = 'https://github.com/everx-labs/TVM-linker' -version = '0.21.5' +version = '0.21.6' [[bin]] name = 'tvm_linker' @@ -30,10 +30,10 @@ serde_json = '1.0' sha2 = '0.10' simplelog = '0.6' thiserror = '1.0' -ever_abi = { git = 'https://github.com/everx-labs/ever-abi.git', tag = '2.6.4' } -ever_assembler = { git = 'https://github.com/everx-labs/ever-assembler.git', tag = '1.6.6' } -ever_block = { git = 'https://github.com/everx-labs/ever-block.git', tag = '1.11.3' } -ever_vm = { git = 'https://github.com/everx-labs/ever-vm.git', tag = '2.2.4' } +ever_abi = { git = 'https://github.com/everx-labs/ever-abi.git', tag = '2.7.2' } +ever_assembler = { git = 'https://github.com/everx-labs/ever-assembler.git', tag = '1.6.14', features = [ 'gosh' ] } +ever_block = { git = 'https://github.com/everx-labs/ever-block.git', tag = '1.11.11', features = [ 'gosh' ] } +ever_vm = { git = 'https://github.com/everx-labs/ever-vm.git', tag = '2.2.12', features = [ 'gosh' ] } [dev-dependencies] assert_cmd = '2.0.5' diff --git a/build.rs b/build.rs index 14a70663..4e32d11d 100644 --- a/build.rs +++ b/build.rs @@ -13,10 +13,7 @@ use std::process::Command; fn from_utf8(data: Vec) -> String { - match String::from_utf8(data) { - Ok(string) => string, - Err(_) => String::from("Unknown") - } + String::from_utf8(data).unwrap_or_else(|_| String::from("Unknown")) } fn main() { diff --git a/src/abi.rs b/src/abi.rs index 788cc7a1..fca40c8b 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -10,11 +10,14 @@ * See the License for the specific EVERX DEV software governing permissions and * limitations under the License. */ -use ever_abi::{Contract, json_abi::{encode_function_call, decode_function_response}}; use anyhow::format_err; +use ever_abi::{ + json_abi::{decode_function_response, encode_function_call}, + Contract, +}; -use ever_block::{BuilderData, Result, SliceData}; use crate::keyman::Keypair; +use ever_block::{BuilderData, Result, SliceData}; pub fn build_abi_body( abi_file: &str, @@ -60,5 +63,3 @@ pub fn decode_body( false, ) } - - diff --git a/src/keyman.rs b/src/keyman.rs index 5b217a76..3bbdf82d 100644 --- a/src/keyman.rs +++ b/src/keyman.rs @@ -11,7 +11,7 @@ * limitations under the License. */ use anyhow::format_err; -use ever_block::{Ed25519PrivateKey, Result, Ed25519PublicKey, ed25519_create_private_key}; +use ever_block::{ed25519_create_private_key, Ed25519PrivateKey, Ed25519PublicKey, Result}; use serde::Deserialize; pub struct Keypair { @@ -35,7 +35,8 @@ impl Keypair { let public = hex::decode(keys.public) .map_err(|e| format_err!("failed to decode public key: {}", e))?; - let public_bytes = public.try_into() + let public_bytes = public + .try_into() .map_err(|v: Vec| format_err!("failed to get public bytes, bad len {}", v.len()))?; Ok(Self { private: ed25519_create_private_key(&private)?, diff --git a/src/main.rs b/src/main.rs index 2036842e..13a00b2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,19 +17,19 @@ mod printer; mod program; mod testcall; -use std::{env, io::Write, fs::File, str::FromStr}; +use anyhow::{bail, format_err}; use clap::{clap_app, ArgMatches}; -use anyhow::{format_err, bail}; +use std::{env, fs::File, io::Write, str::FromStr}; +use ever_block::{AccountId, BocWriter, Result, SliceData, Status, UInt256}; use ever_block::{ - Deserializable, Message, StateInit, Serializable, MsgAddressInt, - ExternalInboundMessageHeader, InternalMessageHeader, MsgAddressIntOrNone, ConfigParams + ConfigParams, Deserializable, ExternalInboundMessageHeader, InternalMessageHeader, Message, + MsgAddressInt, MsgAddressIntOrNone, Serializable, StateInit, }; -use ever_block::{SliceData, Result, Status, AccountId, UInt256, BocWriter}; -use abi::{build_abi_body, decode_body, load_abi_json_string, load_abi_contract}; +use abi::{build_abi_body, decode_body, load_abi_contract, load_abi_json_string}; use keyman::Keypair; -use program::{get_now, save_to_file, load_from_file}; +use program::{get_now, load_from_file, save_to_file}; use testcall::{call_contract, MsgInfo, TestCallParams, TraceLevel}; const DEFAULT_CAPABILITIES: u64 = 0x880116ae; // Default capabilities on the main network @@ -47,7 +47,7 @@ fn linker_main() -> Status { env!("CARGO_PKG_VERSION"), env!("BUILD_GIT_COMMIT"), env!("BUILD_GIT_DATE"), - env!("BUILD_TIME") , + env!("BUILD_TIME"), ); let matches = clap_app!(tvm_linker => (version: build_info.as_str()) @@ -104,7 +104,6 @@ fn linker_main() -> Status { (@setting SubcommandRequired) ).get_matches(); - //SUBCOMMAND TEST if let Some(test_matches) = matches.subcommand_matches("test") { return run_test_subcmd(test_matches); @@ -132,14 +131,16 @@ fn linker_main() -> Status { let msg_body = match msg_matches.value_of("DATA") { Some(data) => { - let buf = hex::decode(data).map_err(|e| format_err!("data argument has invalid format: {}", e))?; + let buf = hex::decode(data) + .map_err(|e| format_err!("data argument has invalid format: {}", e))?; let len = buf.len() * 8; let body = SliceData::from_raw(buf, len); Some(body) - }, - None => { - build_body(msg_matches, msg_matches.value_of("ADDRESS").map(|s| s.to_string()))? - }, + } + None => build_body( + msg_matches, + msg_matches.value_of("ADDRESS").map(|s| s.to_string()), + )?, }; return build_message( @@ -148,8 +149,8 @@ fn linker_main() -> Status { msg_body, msg_matches.is_present("INIT"), &suffix, - msg_matches.is_present("INTERNAL") - ) + msg_matches.is_present("INTERNAL"), + ); } unreachable!() @@ -157,9 +158,9 @@ fn linker_main() -> Status { fn parse_now(now: Option<&str>) -> Result { let now = match now { - Some(now_str) => { - now_str.parse::().map_err(|e| format_err!("failed to parse \"now\" option: {}", e))? - }, + Some(now_str) => now_str + .parse::() + .map_err(|e| format_err!("failed to parse \"now\" option: {}", e))?, None => get_now(), }; Ok(now) @@ -168,7 +169,9 @@ fn parse_now(now: Option<&str>) -> Result { fn parse_ticktock(ticktock: Option<&str>) -> Result> { let error = "invalid ticktock value: must be 0 for tick and -1 for tock."; if let Some(tt) = ticktock { - let tt = tt.parse::().map_err(|e| format_err!("{}: {}", error, e))?; + let tt = tt + .parse::() + .map_err(|e| format_err!("{}: {}", error, e))?; if tt != 0 && tt != -1 { bail!(error) } else { @@ -219,7 +222,7 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { let (buf, buf_bits) = decode_hex_string(hex_str.to_string())?; let body = SliceData::from_raw(buf, buf_bits); (Some(body), Some(matches.value_of("SIGN"))) - }, + } None => (build_body(matches, Some(address.to_string()))?, None), }; @@ -231,8 +234,7 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { let method = matches.value_of("ABI_METHOD"); if let Some(abi_file) = abi_file { if let Some(method) = method { - let result = decode_body(abi_file, method, body, is_internal) - .unwrap_or_default(); + let result = decode_body(abi_file, method, body, is_internal).unwrap_or_default(); println!("{}", result); } } @@ -242,25 +244,23 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { let _abi_contract = match abi_json { Some(abi_file) => Some(load_abi_contract(&load_abi_json_string(abi_file)?)?), - None => None + None => None, }; - let debug_map_filename = matches.value_of("DEBUG_MAP") - .map(|s| s.to_string()) - .or({ - let mut res = Some("debug_map.map.json".to_string()); - if let Some(abi) = abi_json { - let abi_root = abi.trim_end_matches(".abi.json"); - for extension in [".dbg.json", ".debug.json", ".map.json"] { - let dbg_path = format!("{abi_root}{extension}"); - if std::path::Path::new(&dbg_path).exists() { - res = Some(dbg_path); - break; - } + let debug_map_filename = matches.value_of("DEBUG_MAP").map(|s| s.to_string()).or({ + let mut res = Some("debug_map.map.json".to_string()); + if let Some(abi) = abi_json { + let abi_root = abi.trim_end_matches(".abi.json"); + for extension in [".dbg.json", ".debug.json", ".map.json"] { + let dbg_path = format!("{abi_root}{extension}"); + if std::path::Path::new(&dbg_path).exists() { + res = Some(dbg_path); + break; } } - res - }); + } + res + }); if let Some(map) = debug_map_filename.clone() { println!("DEBUG_MAP: {map}"); } @@ -281,7 +281,8 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { msg_info.body = msg.body(); } - let gas_limit = matches.value_of("GASLIMIT") + let gas_limit = matches + .value_of("GASLIMIT") .map(|v| v.parse::()) .transpose()?; @@ -292,7 +293,6 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { trace_level = TraceLevel::Minimal; } - let input = if input.ends_with(".tvc") { input.to_owned() } else { @@ -302,30 +302,36 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { let state_init = load_from_file(&input)?; let config_cell_opt = matches.value_of("CONFIG").and_then(testcall::load_config); - let capabilities = - match config_cell_opt { - Some(ref config_cell) => { - let config_params = ConfigParams::with_address_and_root( - UInt256::from_str(&"5".repeat(64)).unwrap(), // -1:5555... - config_cell.clone()); - config_params.capabilities() - } - None => { - DEFAULT_CAPABILITIES - } - }; - let (_, state_init, is_success) = call_contract(addr, state_init, TestCallParams { - balance: matches.value_of("BALANCE"), - msg_info, - config: config_cell_opt, - key_file: sign, - ticktock, - gas_limit, - action_decoder: if matches.is_present("DECODEC6") { Some(action_decoder) } else { None }, - trace_level, - debug_info: testcall::load_debug_info(&debug_map_filename.unwrap_or("".to_string())), - capabilities - })?; + let capabilities = match config_cell_opt { + Some(ref config_cell) => { + let config_params = ConfigParams::with_address_and_root( + UInt256::from_str(&"5".repeat(64)).unwrap(), // -1:5555... + config_cell.clone(), + ); + config_params.capabilities() + } + None => DEFAULT_CAPABILITIES, + }; + let (_, state_init, is_success) = call_contract( + addr, + state_init, + TestCallParams { + balance: matches.value_of("BALANCE"), + msg_info, + config: config_cell_opt, + key_file: sign, + ticktock, + gas_limit, + action_decoder: if matches.is_present("DECODEC6") { + Some(action_decoder) + } else { + None + }, + trace_level, + debug_info: testcall::load_debug_info(&debug_map_filename.unwrap_or("".to_string())), + capabilities, + }, + )?; if is_success { save_to_file(state_init, Some(&input), 0, false)?; println!("Contract persistent data updated"); @@ -337,22 +343,29 @@ fn run_test_subcmd(matches: &ArgMatches) -> Status { fn build_body(matches: &ArgMatches, address: Option) -> Result> { let mut mask = 0u8; - let abi_file = matches.value_of("ABI_JSON").map(|m| { mask |= 1; m }); - let method_name = matches.value_of("ABI_METHOD").map(|m| { mask |= 2; m }); + let abi_file = matches.value_of("ABI_JSON").map(|m| { + mask |= 1; + m + }); + let method_name = matches.value_of("ABI_METHOD").map(|m| { + mask |= 2; + m + }); let params = matches.value_of("ABI_PARAMS"); let header = matches.value_of("ABI_HEADER"); if mask == 0x3 { - let key_file = matches.value_of("SIGN") + let key_file = matches + .value_of("SIGN") .map(Keypair::from_file) .transpose()?; - let params = params.map_or(Ok("{}".to_owned()), |params| + let params = params.map_or(Ok("{}".to_owned()), |params| { if params.find('{').is_none() { std::fs::read_to_string(params) .map_err(|e| format_err!("failed to load params from file: {}", e)) } else { Ok(params.to_owned()) } - )?; + })?; let is_internal = matches.is_present("INTERNAL"); let body = build_abi_body( abi_file.unwrap(), @@ -385,17 +398,13 @@ fn build_message( None => -1, }; println!("contract address {}", address_str); - let dest_address = MsgAddressInt::with_standart( - None, - wc, - AccountId::from_str(address_str)? - )?; + let dest_address = MsgAddressInt::with_standart(None, wc, AccountId::from_str(address_str)?)?; let mut msg = if internal { let source_address = MsgAddressIntOrNone::Some(MsgAddressInt::with_standart( None, -1, - AccountId::from_str("55".repeat(32).as_str())? + AccountId::from_str("55".repeat(32).as_str())?, )?); Message::with_int_header(InternalMessageHeader { ihr_disabled: true, diff --git a/src/printer.rs b/src/printer.rs index 24cc1bf3..c32250ad 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -11,17 +11,27 @@ * limitations under the License. */ use anyhow::format_err; -use ever_block::*; use ever_block::write_boc; +use ever_block::*; use ever_block::{BuilderData, Cell, Result}; fn get_version(root: &Cell) -> Result { - let cell1 = root.reference(0).map_err(|e| format_err!("not found ({})", e))?; - let cell2 = cell1.reference(1).map_err(|e| format_err!("not found ({})", e))?; + let cell1 = root + .reference(0) + .map_err(|e| format_err!("not found ({})", e))?; + let cell2 = cell1 + .reference(1) + .map_err(|e| format_err!("not found ({})", e))?; let bytes = cell2.data(); match String::from_utf8(bytes.to_vec()) { - Ok(string) => if string.is_empty() { Ok("".to_string()) } else { Ok(string) }, - Err(e) => Err(format_err!("decoding failed ({})", e)) + Ok(string) => { + if string.is_empty() { + Ok("".to_string()) + } else { + Ok(string) + } + } + Err(e) => Err(format_err!("decoding failed ({})", e)), } } @@ -53,13 +63,11 @@ pub fn state_init_printer(state: &StateInit) -> String { pub fn tree_of_cells_into_base64(root_cell: Option<&Cell>) -> String { match root_cell { - Some(cell) => { - match write_boc(cell) { - Ok(bytes) => base64::encode(bytes), - Err(_) => "None".to_string() - } - } - None => "None".to_string() + Some(cell) => match write_boc(cell) { + Ok(bytes) => base64::encode(bytes), + Err(_) => "None".to_string(), + }, + None => "None".to_string(), } } @@ -67,11 +75,13 @@ pub fn msg_printer(msg: &Message) -> Result { let mut b = BuilderData::new(); msg.write_to(&mut b)?; let bytes = write_boc(&b.into_cell()?)?; - Ok(format!("message header\n{}init : {}\nbody : {}\nbody_hex: {}\nbody_base64: {}\nboc_base64: {}\n", + Ok(format!( + "message header\n{}init : {}\nbody : {}\nbody_hex: {}\nbody_base64: {}\nboc_base64: {}\n", print_msg_header(msg.header()), - msg.state_init().as_ref().map(|x| { - state_init_printer(x) - }).unwrap_or_else(|| "None".to_string()), + msg.state_init() + .as_ref() + .map(|x| { state_init_printer(x) }) + .unwrap_or_else(|| "None".to_string()), match msg.body() { Some(slice) => format!("{:.2}", slice.into_cell()), None => "None".to_string(), @@ -79,11 +89,7 @@ pub fn msg_printer(msg: &Message) -> Result { msg.body() .map(|b| hex::encode(b.get_bytestring(0))) .unwrap_or_else(|| "None".to_string()), - tree_of_cells_into_base64( - msg.body() - .map(|slice| slice.into_cell()) - .as_ref(), - ), + tree_of_cells_into_base64(msg.body().map(|slice| slice.into_cell()).as_ref(),), base64::encode(bytes), )) } @@ -91,27 +97,27 @@ pub fn msg_printer(msg: &Message) -> Result { fn print_msg_header(header: &CommonMsgInfo) -> String { match header { CommonMsgInfo::IntMsgInfo(header) => { - format!(" ihr_disabled: {}\n", header.ihr_disabled) + - &format!(" bounce : {}\n", header.bounce) + - &format!(" bounced : {}\n", header.bounced) + - &format!(" source : {}\n", &header.src) + - &format!(" destination : {}\n", &header.dst) + - &format!(" value : {}\n", print_cc(&header.value)) + - &format!(" ihr_fee : {}\n", print_grams(&header.ihr_fee)) + - &format!(" fwd_fee : {}\n", print_grams(&header.fwd_fee)) + - &format!(" created_lt : {}\n", header.created_lt) + - &format!(" created_at : {}\n", header.created_at) - }, + format!(" ihr_disabled: {}\n", header.ihr_disabled) + + &format!(" bounce : {}\n", header.bounce) + + &format!(" bounced : {}\n", header.bounced) + + &format!(" source : {}\n", &header.src) + + &format!(" destination : {}\n", &header.dst) + + &format!(" value : {}\n", print_cc(&header.value)) + + &format!(" ihr_fee : {}\n", print_grams(&header.ihr_fee)) + + &format!(" fwd_fee : {}\n", print_grams(&header.fwd_fee)) + + &format!(" created_lt : {}\n", header.created_lt) + + &format!(" created_at : {}\n", header.created_at) + } CommonMsgInfo::ExtInMsgInfo(header) => { - format!( " source : {}\n", &header.src) + - &format!(" destination : {}\n", &header.dst) + - &format!(" import_fee : {}\n", print_grams(&header.import_fee)) - }, + format!(" source : {}\n", &header.src) + + &format!(" destination : {}\n", &header.dst) + + &format!(" import_fee : {}\n", print_grams(&header.import_fee)) + } CommonMsgInfo::ExtOutMsgInfo(header) => { - format!( " source : {}\n", &header.src) + - &format!(" destination : {}\n", &header.dst) + - &format!(" created_lt : {}\n", header.created_lt) + - &format!(" created_at : {}\n", header.created_at) + format!(" source : {}\n", &header.src) + + &format!(" destination : {}\n", &header.dst) + + &format!(" created_lt : {}\n", header.created_lt) + + &format!(" created_at : {}\n", header.created_at) } } } @@ -124,10 +130,12 @@ fn print_cc(cc: &CurrencyCollection) -> String { let mut result = print_grams(&cc.grams); if !cc.other.is_empty() { result += " other: {"; - cc.other.iterate_with_keys(|key: u32, value| { - result += &format!(" \"{}\": \"{}\",", key, value); - Ok(true) - }).ok(); + cc.other + .iterate_with_keys(|key: u32, value| { + result += &format!(" \"{}\": \"{}\",", key, value); + Ok(true) + }) + .ok(); result.pop(); // remove extra comma result += " }"; } @@ -140,8 +148,16 @@ fn check_output_for_money() { assert_eq!(print_grams(&cc.grams), "72057594037927935"); assert_eq!(print_cc(&cc), "72057594037927935"); cc.set_other(12, 125).unwrap(); - cc.set_other_ex(17, &VarUInteger32::from_two_u128(1, 1900).unwrap()).unwrap(); - cc.set_other_ex(u32::MAX, &VarUInteger32::from_two_u128(u128::MAX >> 8, u128::MAX).unwrap()).unwrap(); + cc.set_other_ex(17, &VarUInteger32::from_two_u128(1, 1900).unwrap()) + .unwrap(); + cc.set_other_ex( + u32::MAX, + &VarUInteger32::from_two_u128(u128::MAX >> 8, u128::MAX).unwrap(), + ) + .unwrap(); assert_eq!(print_grams(&cc.grams), "72057594037927935"); - assert_eq!(print_cc(&cc), r#"72057594037927935 other: { "12": "125", "17": "340282366920938463463374607431768213356", "4294967295": "452312848583266388373324160190187140051835877600158453279131187530910662655" }"#); + assert_eq!( + print_cc(&cc), + r#"72057594037927935 other: { "12": "125", "17": "340282366920938463463374607431768213356", "4294967295": "452312848583266388373324160190187140051835877600158453279131187530910662655" }"# + ); } diff --git a/src/program.rs b/src/program.rs index f4017e01..286d0f6d 100644 --- a/src/program.rs +++ b/src/program.rs @@ -15,12 +15,10 @@ use base64::encode; use std::fs::File; use std::io::{Read, Write}; -use std::time::SystemTime; use ever_block::*; +use std::time::SystemTime; -use ever_block::{ - read_boc, Cell, SliceData, BuilderData, Result, -}; +use ever_block::{read_boc, BuilderData, Cell, Result, SliceData}; const XMODEM: crc::Crc = crc::Crc::::new(&crc::CRC_16_XMODEM); @@ -45,11 +43,23 @@ pub fn save_to_file(state: StateInit, name: Option<&str>, wc: i8, silent: bool) } else { println!("Saved contract to file {}", &file_name); println!("testnet:"); - println!("Non-bounceable address (for init): {}", &calc_userfriendly_address(wc, address.as_slice(), false, true)); - println!("Bounceable address (for later access): {}", &calc_userfriendly_address(wc, address.as_slice(), true, true)); + println!( + "Non-bounceable address (for init): {}", + &calc_userfriendly_address(wc, address.as_slice(), false, true) + ); + println!( + "Bounceable address (for later access): {}", + &calc_userfriendly_address(wc, address.as_slice(), true, true) + ); println!("mainnet:"); - println!("Non-bounceable address (for init): {}", &calc_userfriendly_address(wc, address.as_slice(), false, false)); - println!("Bounceable address (for later access): {}", &calc_userfriendly_address(wc, address.as_slice(), true, false)); + println!( + "Non-bounceable address (for init): {}", + &calc_userfriendly_address(wc, address.as_slice(), false, false) + ); + println!( + "Bounceable address (for later access): {}", + &calc_userfriendly_address(wc, address.as_slice(), true, false) + ); } } Ok(file_name) @@ -82,7 +92,8 @@ pub fn load_stateinit(file_name: &str) -> Result<(SliceData, Vec)> { f.read_to_end(&mut orig_bytes)?; let mut root = read_boc(orig_bytes.clone())?.roots.remove(0); - if root.references_count() == 2 { // append empty library cell + if root.references_count() == 2 { + // append empty library cell let mut adjusted_cell = BuilderData::from_cell(&root)?; adjusted_cell.checked_append_reference(Cell::default())?; root = adjusted_cell.into_cell()?; @@ -91,7 +102,10 @@ pub fn load_stateinit(file_name: &str) -> Result<(SliceData, Vec)> { } pub fn get_now() -> u32 { - SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as u32 + SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() as u32 } #[cfg(test)] @@ -100,7 +114,8 @@ mod tests { #[test] fn test_bouncable_address() { - let addr = hex::decode("fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260").unwrap(); + let addr = hex::decode("fcb91a3a3816d0f7b8c2c76108b8a9bc5a6b7a55bd79f8ab101c52db29232260") + .unwrap(); let addr = calc_userfriendly_address(-1, &addr, true, true); assert_eq!(addr, "kf/8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15+KsQHFLbKSMiYIny"); } diff --git a/src/testcall.rs b/src/testcall.rs index e715f000..354beeb8 100644 --- a/src/testcall.rs +++ b/src/testcall.rs @@ -14,35 +14,40 @@ use std::{fs::File, str::FromStr, sync::Arc}; use anyhow::format_err; -use log::{log_enabled, Level::Error}; -use simplelog::{SimpleLogger, Config, LevelFilter}; -use serde_json::Value; +use ever_assembler::DbgInfo; +use ever_block::{ + ed25519_sign_with_secret, AccountId, BuilderData, Cell, HashmapE, Result, SliceData, Status, +}; +use ever_block::{ + CurrencyCollection, Deserializable, ExternalInboundMessageHeader, Grams, InternalMessageHeader, + Message, MsgAddressExt, MsgAddressInt, OutAction, OutActions, Serializable, StateInit, +}; use ever_vm::{ - int, - executor::{Engine, EngineTraceInfo, EngineTraceInfoType, gas::gas_state::Gas}, error::tvm_exception, - stack::{StackItem, Stack, savelist::SaveList, integer::IntegerData}, + executor::{gas::gas_state::Gas, Engine, EngineTraceInfo, EngineTraceInfoType}, + int, + stack::{integer::IntegerData, savelist::SaveList, Stack, StackItem}, SmartContractInfo, }; -use ever_block::{AccountId, BuilderData, Cell, SliceData, Result, Status, HashmapE, ed25519_sign_with_secret}; -use ever_block::{ - CurrencyCollection, Deserializable, ExternalInboundMessageHeader, Grams, - InternalMessageHeader, Message, MsgAddressExt, MsgAddressInt, OutAction, - OutActions, Serializable, StateInit, -}; -use ever_assembler::DbgInfo; +use log::{log_enabled, Level::Error}; +use serde_json::Value; +use simplelog::{Config, LevelFilter, SimpleLogger}; use crate::keyman::Keypair; use crate::printer::msg_printer; -use crate::program::{load_from_file, get_now}; +use crate::program::{get_now, load_from_file}; const DEFAULT_ACCOUNT_BALANCE: &str = "100000000000"; -fn create_external_inbound_msg(src: MsgAddressExt, dst: MsgAddressInt, body: Option) -> Message { +fn create_external_inbound_msg( + src: MsgAddressExt, + dst: MsgAddressInt, + body: Option, +) -> Message { let hdr = ExternalInboundMessageHeader { dst, src, - import_fee: 0x1234u64.into() + import_fee: 0x1234u64.into(), }; let mut msg = Message::with_ext_in_header(hdr); if let Some(body) = body { @@ -60,11 +65,7 @@ fn create_internal_msg( body: Option, bounced: bool, ) -> Message { - let mut hdr = InternalMessageHeader::with_addresses( - src_addr, - dst_addr, - value, - ); + let mut hdr = InternalMessageHeader::with_addresses(src_addr, dst_addr, value); hdr.bounce = !bounced; hdr.bounced = bounced; hdr.ihr_disabled = true; @@ -84,7 +85,8 @@ fn sign_body(body: &mut SliceData, key_file: Option<&str>) -> Status { if let Some(f) = key_file { let pair = Keypair::from_file(f)?; let pub_key = pair.public.to_bytes(); - let signature = ed25519_sign_with_secret(pair.private.as_bytes(), body.cell().repr_hash().as_slice())?; + let signature = + ed25519_sign_with_secret(pair.private.as_bytes(), body.cell().repr_hash().as_slice())?; sign_builder.append_raw(&signature, signature.len() * 8)?; sign_builder.append_raw(&pub_key, pub_key.len() * 8)?; } @@ -120,13 +122,23 @@ fn initialize_registers( fn init_logger(debug: bool) -> Status { SimpleLogger::init( - if debug {LevelFilter::Trace } else { LevelFilter::Info }, - Config { time: None, level: None, target: None, location: None, time_format: None, ..Default::default() }, + if debug { + LevelFilter::Trace + } else { + LevelFilter::Info + }, + Config { + time: None, + level: None, + target: None, + location: None, + time_format: None, + ..Default::default() + }, )?; Ok(()) } - fn create_inbound_msg( selector: i32, msg_info: &MsgInfo, @@ -148,15 +160,12 @@ fn create_inbound_msg( msg_info.body.clone(), msg_info.bounced, )) - }, + } -1 => { let src = match msg_info.src { Some(s) => MsgAddressExt::from_str(s)?, - None => { - MsgAddressExt::with_extern( - SliceData::from_raw(vec![0x55; 8], 64) - ).map_err(|e| format_err!("Failed to create address: {}", e))? - }, + None => MsgAddressExt::with_extern(SliceData::from_raw(vec![0x55; 8], 64)) + .map_err(|e| format_err!("Failed to create address: {}", e))?, }; Some(create_external_inbound_msg( src, @@ -164,35 +173,36 @@ fn create_inbound_msg( .map_err(|e| format_err!("Failed to convert address: {}", e))?, msg_info.body.clone(), )) - }, + } _ => None, }) } fn decode_actions(actions: StackItem, state: &mut StateInit, action_decoder: F) -> Status - where F: Fn(SliceData, bool) +where + F: Fn(SliceData, bool), { if let StackItem::Cell(cell) = &actions { let actions: OutActions = OutActions::construct_from(&mut SliceData::load_cell_ref(cell)?)?; println!("Output actions:\n----------------"); for act in actions { match act { - OutAction::SendMsg{mode: _, out_msg } => { + OutAction::SendMsg { mode: _, out_msg } => { println!("Action(SendMsg):\n{}", msg_printer(&out_msg)?); if let Some(b) = out_msg.body() { action_decoder(b, out_msg.is_internal()); } - }, - OutAction::SetCode{ new_code: code } => { + } + OutAction::SetCode { new_code: code } => { println!("Action(SetCode)"); state.code = Some(code); - }, + } OutAction::ReserveCurrency { .. } => { println!("Action(ReserveCurrency)"); - }, + } OutAction::ChangeLibrary { .. } => { println!("Action(ChangeLibrary)"); - }, + } _ => println!("Action(Unknown)"), }; } @@ -201,7 +211,8 @@ fn decode_actions(actions: StackItem, state: &mut StateInit, action_decoder: } pub fn load_code_and_data(state_init: &StateInit) -> (SliceData, SliceData) { - let code: SliceData = SliceData::load_cell(state_init.code.clone().unwrap_or_default()).unwrap(); + let code: SliceData = + SliceData::load_cell(state_init.code.clone().unwrap_or_default()).unwrap(); let data = SliceData::load_cell(state_init.data.clone().unwrap_or_default()).unwrap(); (code, data) } @@ -212,24 +223,31 @@ fn decode_balance(value: Option<&str>) -> Result<(u64, CurrencyCollection)> { Ok((main, CurrencyCollection::with_grams(main))) } else { let err_msg = "invalid extra currencies"; - let v: Value = serde_json::from_str(value).map_err(|e| format_err!("{}: {}", err_msg, e))?; + let v: Value = + serde_json::from_str(value).map_err(|e| format_err!("{}: {}", err_msg, e))?; - let main = v.get("main").and_then(|main| { main.as_u64() }) + let main = v + .get("main") + .and_then(|main| main.as_u64()) .ok_or_else(|| format_err!("invalid main currency"))?; let mut currencies = CurrencyCollection::with_grams(main); - v.get("extra").and_then(|extra| { - extra.as_object().and_then(|extra| { - for (i, val) in extra { - let key = i.parse::().ok()?; - let amount = val.as_u64()?; - currencies.set_other(key, amount as u128) - .map_err(|e| println!("Failed to update currencies: {}", e)).unwrap_or_default(); - } - Some(()) + v.get("extra") + .and_then(|extra| { + extra.as_object().and_then(|extra| { + for (i, val) in extra { + let key = i.parse::().ok()?; + let amount = val.as_u64()?; + currencies + .set_other(key, amount as u128) + .map_err(|e| println!("Failed to update currencies: {}", e)) + .unwrap_or_default(); + } + Some(()) + }) }) - }).ok_or_else(|| format_err!("{}", err_msg))?; + .ok_or_else(|| format_err!("{}", err_msg))?; Ok((main, currencies)) } } @@ -245,7 +263,7 @@ pub struct MsgInfo<'a> { pub fn load_debug_info(filename: &str) -> Option { File::open(filename) .ok() - .and_then(|file| { serde_json::from_reader(file).ok() }) + .and_then(|file| serde_json::from_reader(file).ok()) .flatten() } @@ -260,7 +278,7 @@ pub fn load_config(filename: &str) -> Option { pub enum TraceLevel { Full, Minimal, - None + None, } fn get_position(info: &EngineTraceInfo, debug_info: &Option) -> Option { @@ -270,43 +288,46 @@ fn get_position(info: &EngineTraceInfo, debug_info: &Option) -> Option< let position = match debug_info.get(&cell_hash) { Some(offset_map) => match offset_map.get(&offset) { Some(pos) => format!("{}:{}", pos.filename, pos.line), - None => String::from("-:0 (offset not found)") + None => String::from("-:0 (offset not found)"), }, - None => String::from("-:0 (cell hash not found)") + None => String::from("-:0 (cell hash not found)"), }; - return Some(position) + return Some(position); } None } fn trace_callback_minimal(_engine: &Engine, info: &EngineTraceInfo, debug_info: &Option) { - print!("{} {} {} {}", info.step, info.gas_used, info.gas_cmd, info.cmd_str); - let position = get_position(info, debug_info); + print!( + "{} {} {} {}", + info.step, info.gas_used, info.gas_cmd, info.cmd_str + ); + let position = get_position(info, debug_info); if position.is_some() { print!(" {}", position.unwrap()); } println!(); } -fn trace_callback(_engine: &Engine, info: &EngineTraceInfo, extended: bool, debug_info: &Option) { +fn trace_callback( + _engine: &Engine, + info: &EngineTraceInfo, + extended: bool, + debug_info: &Option, +) { if info.info_type == EngineTraceInfoType::Dump { println!("{}", info.cmd_str); - return + return; } - println!("{}: {}", - info.step, - info.cmd_str - ); + println!("{}: {}", info.step, info.cmd_str); if extended { - println!("{} {}", + println!( + "{} {}", info.cmd_code.remaining_bits(), info.cmd_code.to_hex_string() ); } - println!("\nGas: {} ({})", - info.gas_used, - info.gas_cmd - ); + println!("\nGas: {} ({})", info.gas_used, info.gas_cmd); let position = get_position(info, debug_info); if position.is_some() { println!("Position: {}", position.unwrap()); @@ -328,7 +349,7 @@ pub struct TestCallParams<'a, F: Fn(SliceData, bool)> { pub action_decoder: Option, pub trace_level: TraceLevel, pub debug_info: Option, - pub capabilities: u64 + pub capabilities: u64, } pub fn call_contract( @@ -336,11 +357,18 @@ pub fn call_contract( state_init: StateInit, params: TestCallParams, ) -> Result<(i32, StateInit, bool)> - where F: Fn(SliceData, bool) +where + F: Fn(SliceData, bool), { let func_selector = match params.msg_info.balance { Some(_) => 0, - None => if params.ticktock.is_some() { -2 } else { -1 }, + None => { + if params.ticktock.is_some() { + -2 + } else { + -1 + } + } }; let msg = create_inbound_msg(func_selector, ¶ms.msg_info, addr.address())?; @@ -360,19 +388,17 @@ pub fn call_contract( params.msg_info.now, smc_balance, params.config, - params.capabilities + params.capabilities, )?; let mut stack = Stack::new(); if func_selector > -2 { let msg_cell = StackItem::Cell( - msg.ok_or_else(|| format_err!("Failed to create message"))?.serialize()? + msg.ok_or_else(|| format_err!("Failed to create message"))? + .serialize()?, ); - let mut body = match params.msg_info.body { - Some(b) => b, - None => SliceData::default(), - }; + let mut body = params.msg_info.body.unwrap_or_default(); if func_selector == -1 { if let Some(key_file) = params.key_file { @@ -387,11 +413,11 @@ pub fn call_contract( }; stack - .push(int!(smc_value)) // contract balance - .push(int!(msg_value)) // msg value - .push(msg_cell) // whole msg + .push(int!(smc_value)) // contract balance + .push(int!(msg_value)) // msg value + .push(msg_cell) // whole msg .push(StackItem::Slice(body)) // msg body - .push(int!(func_selector)); //selector + .push(int!(func_selector)); //selector } else { let addr_val = addr.address().to_hex_string(); let addr_int = IntegerData::from_str_radix(&addr_val, 16)?; @@ -413,28 +439,31 @@ pub fn call_contract( let library_map = HashmapE::with_hashmap(256, state_init.library.root().cloned()); println!("Engine capabilities: {}", params.capabilities); - let mut engine = Engine::with_capabilities( - params.capabilities - ).setup_with_libraries( - code, Some(registers), Some(stack), Some(gas), vec!(library_map) + let mut engine = Engine::with_capabilities(params.capabilities).setup_with_libraries( + code, + Some(registers), + Some(stack), + Some(gas), + vec![library_map], ); engine.set_trace(0); let debug_info = params.debug_info; match params.trace_level { - TraceLevel::Full => engine.set_trace_callback(move |engine, info| { trace_callback(engine, info, true, &debug_info); }), - TraceLevel::Minimal => engine.set_trace_callback(move |engine, info| { trace_callback_minimal(engine, info, &debug_info); }), + TraceLevel::Full => engine.set_trace_callback(move |engine, info| { + trace_callback(engine, info, true, &debug_info); + }), + TraceLevel::Minimal => engine.set_trace_callback(move |engine, info| { + trace_callback_minimal(engine, info, &debug_info); + }), TraceLevel::None => {} } - let exit_code = match engine.execute() { - Err(exc) => match tvm_exception(exc) { - Ok(exc) => { - println!("Unhandled exception: {}", exc); - exc.exception_or_custom_code() - } - _ => -1 + let exit_code = engine.execute().unwrap_or_else(|exc| match tvm_exception(exc) { + Ok(exc) => { + println!("Unhandled exception: {}", exc); + exc.exception_or_custom_code() } - Ok(code) => code, - }; + _ => -1, + }); let is_vm_success = engine.get_committed_state().is_committed(); println!("TVM terminated with exit code {}", exit_code); @@ -475,9 +504,7 @@ mod tests { #[test] fn test_msg_print() { let msg = create_external_inbound_msg( - MsgAddressExt::with_extern( - SliceData::from_raw(vec![0x55; 8], 64) - ).unwrap(), + MsgAddressExt::with_extern(SliceData::from_raw(vec![0x55; 8], 64)).unwrap(), MsgAddressInt::with_standart(None, 0, [0x11; 32].into()).unwrap(), Some(SliceData::load_cell(create_inbound_body(10, 20, 0x11223344).unwrap()).unwrap()), ); @@ -492,13 +519,20 @@ mod tests { false, ); - println!("SendMsg action:\n{}", msg_printer(&msg).unwrap_or("Undefined".to_string())); - println!("SendMsg action:\n{}", msg_printer(&msg).unwrap_or("Undefined".to_string())); + println!( + "SendMsg action:\n{}", + msg_printer(&msg).unwrap_or("Undefined".to_string()) + ); + println!( + "SendMsg action:\n{}", + msg_printer(&msg).unwrap_or("Undefined".to_string()) + ); } #[test] fn test_decode_balance() { - let (main, balance) = decode_balance(Some(r#"{ "main": 100, "extra": {"0": 33, "50": 99} }"#)).unwrap(); + let (main, balance) = + decode_balance(Some(r#"{ "main": 100, "extra": {"0": 33, "50": 99} }"#)).unwrap(); assert_eq!(main, 100); let mut expected_balance = CurrencyCollection::with_grams(100); expected_balance.set_other(0, 33).unwrap(); @@ -513,7 +547,7 @@ mod tests { #[test] fn test_decode_balance_default() { let (main, balance) = decode_balance(None).unwrap(); - let expected = u64::from_str_radix(DEFAULT_ACCOUNT_BALANCE, 10).unwrap(); + let expected = DEFAULT_ACCOUNT_BALANCE.parse::().unwrap(); assert_eq!(main, expected); assert_eq!(balance, CurrencyCollection::with_grams(expected)); } @@ -521,15 +555,15 @@ mod tests { #[test] fn test_decode_balance_invalid() { let err = decode_balance(Some(r#"{ "main": 100 }"#)); - assert_eq!(err.is_err(), true); + assert!(err.is_err()); let err = decode_balance(Some(r#"{ "main": qwe }"#)); - assert_eq!(err.is_err(), true); + assert!(err.is_err()); let err = decode_balance(Some(r#"{ "main": 0, extra: {"dd": 10} }"#)); - assert_eq!(err.is_err(), true); + assert!(err.is_err()); let err = decode_balance(Some(r#"{ "main": 0, extra: {"0": qwe} }"#)); - assert_eq!(err.is_err(), true); + assert!(err.is_err()); } } From edf73c3a1cf9a54f1e998e725257e26db05c0987 Mon Sep 17 00:00:00 2001 From: tonjen Date: Thu, 15 Aug 2024 22:10:28 +0000 Subject: [PATCH 2/2] Preparing to merge with the master #nolog --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80f703c5..52ed7bef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,9 @@ sha2 = '0.10' simplelog = '0.6' thiserror = '1.0' ever_abi = { git = 'https://github.com/everx-labs/ever-abi.git', tag = '2.7.2' } -ever_assembler = { git = 'https://github.com/everx-labs/ever-assembler.git', tag = '1.6.14', features = [ 'gosh' ] } -ever_block = { git = 'https://github.com/everx-labs/ever-block.git', tag = '1.11.11', features = [ 'gosh' ] } -ever_vm = { git = 'https://github.com/everx-labs/ever-vm.git', tag = '2.2.12', features = [ 'gosh' ] } +ever_assembler = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-assembler.git', tag = '1.6.14' } +ever_block = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-block.git', tag = '1.11.11' } +ever_vm = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-vm.git', tag = '2.2.12' } [dev-dependencies] assert_cmd = '2.0.5'