diff --git a/Cargo.lock b/Cargo.lock index bc229fab9..0b53a39d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ "actix-macros", "actix-rt", "actix_derive", - "bitflags 2.4.0", + "bitflags 2.4.1", "bytes", "crossbeam-channel", "futures-core", @@ -24,7 +24,7 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", - "tokio-util 0.7.9", + "tokio-util 0.7.10", ] [[package]] @@ -87,24 +87,14 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom 0.2.10", - "once_cell", - "version_check", -] - -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -187,9 +177,9 @@ checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "arbitrary" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e" +checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859" dependencies = [ "derive_arbitrary", ] @@ -223,9 +213,9 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.5.4" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1da3ae8dabd9c00f453a329dfe1fb28da3c0a72e2478cdcd93171740c20499" +checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0" dependencies = [ "async-lock", "async-task", @@ -261,7 +251,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.24", + "rustix 0.37.27", "slab", "socket2", "waker-fn", @@ -289,7 +279,7 @@ dependencies = [ "cfg-if", "event-listener 3.0.0", "futures-lite", - "rustix 0.38.18", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -316,7 +306,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.18", + "rustix 0.38.21", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -346,15 +336,15 @@ dependencies = [ [[package]] name = "async-task" -version = "4.4.1" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9441c6b2fe128a7c2bf680a44c34d0df31ce09e5b7e401fcca3faa483dbc921" +checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", @@ -407,9 +397,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.4" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "bip39" @@ -438,9 +428,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "blake2" @@ -503,16 +493,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "borsh" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" -dependencies = [ - "borsh-derive 0.9.3", - "hashbrown 0.11.2", -] - [[package]] name = "borsh" version = "0.10.3" @@ -524,16 +504,13 @@ dependencies = [ ] [[package]] -name = "borsh-derive" -version = "0.9.3" +name = "borsh" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" +checksum = "5e3f7359eeed8d454c38bbb25eb89d98b888b1060bbfeed2cda71cb013ff2dc2" dependencies = [ - "borsh-derive-internal 0.9.3", - "borsh-schema-derive-internal 0.9.3", - "proc-macro-crate 0.1.5", - "proc-macro2", - "syn 1.0.109", + "borsh-derive 1.1.1", + "cfg_aliases", ] [[package]] @@ -542,22 +519,25 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" dependencies = [ - "borsh-derive-internal 0.10.3", - "borsh-schema-derive-internal 0.10.3", + "borsh-derive-internal", + "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", ] [[package]] -name = "borsh-derive-internal" -version = "0.9.3" +name = "borsh-derive" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" +checksum = "318d18ba283f9aa5bfef1405996ce66c584127f401be1403729ec88b10adc772" dependencies = [ + "once_cell", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.38", + "syn_derive", ] [[package]] @@ -571,17 +551,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "borsh-schema-derive-internal" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "borsh-schema-derive-internal" version = "0.10.3" @@ -682,6 +651,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.31" @@ -717,9 +692,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.6" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" dependencies = [ "clap_builder", "clap_derive", @@ -727,9 +702,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.6" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" dependencies = [ "anstream", "anstyle", @@ -739,9 +714,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -751,9 +726,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "color-eyre" @@ -852,9 +827,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ "libc", ] @@ -1031,10 +1006,11 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" dependencies = [ + "powerfmt", "serde", ] @@ -1211,9 +1187,9 @@ dependencies = [ [[package]] name = "enum-map" -version = "2.6.3" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c188012f8542dee7b3996e44dd89461d64aa471b0a7c71a1ae2f595d259e96e5" +checksum = "53337c2dbf26a3c31eccc73a37b10c1614e8d4ae99b6a50d553e8936423c1f16" dependencies = [ "enum-map-derive", ] @@ -1337,9 +1313,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -1387,9 +1363,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", @@ -1402,9 +1378,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", "futures-sink", @@ -1412,15 +1388,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" dependencies = [ "futures-core", "futures-task", @@ -1429,9 +1405,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" @@ -1450,9 +1426,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", @@ -1461,21 +1437,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-channel", "futures-core", @@ -1542,19 +1518,10 @@ dependencies = [ "indexmap 1.9.3", "slab", "tokio", - "tokio-util 0.7.9", + "tokio-util 0.7.10", "tracing", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash 0.7.6", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1567,14 +1534,14 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.3", + "ahash", ] [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -1755,16 +1722,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -1816,7 +1783,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.1", + "hashbrown 0.14.2", "serde", ] @@ -1894,9 +1861,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-docker" @@ -1914,7 +1881,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.18", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -2063,9 +2030,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -2118,9 +2085,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", @@ -2221,6 +2188,7 @@ dependencies = [ "near-ledger", "near-primitives", "near-socialdb-client", + "near-token", "open", "openssl", "prettytable", @@ -2291,13 +2259,12 @@ dependencies = [ [[package]] name = "near-gas" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dac82d80f9dba5d879876ccee0fc8f4d91ca82552bad545e9f9714c5da49e4c" +checksum = "95b30860db1eceba9b445dc56558a0fdcdfe29fd612a088e697b32dfb681aaac" dependencies = [ - "borsh 0.9.3", + "borsh 1.1.1", "interactive-clap", - "schemars", "serde", ] @@ -2419,7 +2386,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "775fec19ef51a341abdbf792a9dda5b4cb89f488f681b2fd689b9321d24db47b" dependencies = [ "arbitrary", - "base64 0.21.4", + "base64 0.21.5", "borsh 0.10.3", "bs58 0.4.0", "derive_more", @@ -2459,16 +2426,16 @@ dependencies = [ [[package]] name = "near-socialdb-client" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0c8308868cc23a386607d73bc04b9fb8ce054e3f7bd3392899daf5d29b8b443" +checksum = "6d95eb83d682b043d6c9662e94ad4b06398b0474c891e0bd9d9470516a97371e" dependencies = [ "color-eyre", - "interactive-clap", "near-crypto", "near-jsonrpc-client", "near-jsonrpc-primitives", "near-primitives", + "near-token", "serde", "serde_json", "url", @@ -2480,6 +2447,17 @@ version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6540152fba5e96fe5d575b79e8cd244cf2add747bb01362426bdc069bc3a23bc" +[[package]] +name = "near-token" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b68f3f8a2409f72b43efdbeff8e820b81e70824c49fee8572979d789d1683fb" +dependencies = [ + "borsh 1.1.1", + "interactive-clap", + "serde", +] + [[package]] name = "near-vm-errors" version = "0.17.0" @@ -2685,7 +2663,7 @@ version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "cfg-if", "foreign-types", "libc", @@ -2713,9 +2691,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.1.5+3.1.3" +version = "300.1.6+3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559068e4c12950d7dcaa1857a61725c0d38d4fc03ff8e070ab31a75d6e316491" +checksum = "439fac53e092cd7442a3660c85dde4643ab3b5bd39040912388dcdabf6b88085" dependencies = [ "cc", ] @@ -2811,9 +2789,9 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "parking" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e52c774a4c39359c1d1c52e43f73dd91a75a614652c825408eec30c95a9b2067" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "parking_lot" @@ -2827,13 +2805,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall 0.4.1", "smallvec", "windows-targets 0.48.5", ] @@ -2927,9 +2905,15 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31114a898e107c51bb1609ffaf55a0e011cf6a4d7f1170d0015a165082c0338b" +checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" @@ -3194,6 +3178,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -3216,14 +3209,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.0" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.1", - "regex-syntax 0.8.0", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -3237,13 +3230,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.0", + "regex-syntax 0.8.2", ] [[package]] @@ -3254,9 +3247,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3cbb081b9784b07cceb8824c8583f86db4814d172ab043f3c23f7dc600bf83d" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" @@ -3264,7 +3257,7 @@ version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", "bytes", "encoding_rs", "futures-core", @@ -3313,9 +3306,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.24" +version = "0.37.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4279d76516df406a8bd37e7dff53fd37d1a093f997a3c34a5c21658c126db06d" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", @@ -3327,11 +3320,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.18" +version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys 0.4.10", @@ -3368,30 +3361,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "schemars" -version = "0.8.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 1.0.109", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -3488,35 +3457,24 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", "syn 2.0.38", ] -[[package]] -name = "serde_derive_internals" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "serde_json" version = "1.0.107" @@ -3541,9 +3499,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" dependencies = [ "serde", ] @@ -3562,11 +3520,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca3b16a3d82c4088f343b7480a93550b3eabe1a358569c2dfe38bbcead07237" +checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", "chrono", "hex 0.4.3", "indexmap 1.9.3", @@ -3579,9 +3537,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e6be15c453eb305019bfa438b1593c731f36a289a7853f7707ee29e870b3b3c" +checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788" dependencies = [ "darling", "proc-macro2", @@ -3591,9 +3549,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.25" +version = "0.9.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" +checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" dependencies = [ "indexmap 2.0.2", "itoa", @@ -3775,9 +3733,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", @@ -3845,6 +3803,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -3879,14 +3849,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand 2.0.1", - "redox_syscall 0.3.5", - "rustix 0.38.18", + "redox_syscall 0.4.1", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -3903,18 +3873,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", @@ -3933,12 +3903,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", "itoa", + "powerfmt", "serde", "time-core", "time-macros", @@ -4051,9 +4022,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", @@ -4086,9 +4057,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -4163,7 +4134,7 @@ dependencies = [ "rand 0.8.5", "slab", "tokio", - "tokio-util 0.7.9", + "tokio-util 0.7.10", "tower-layer", "tower-service", "tracing", @@ -4183,11 +4154,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -4207,9 +4177,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", @@ -4218,9 +4188,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -4248,12 +4218,12 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" dependencies = [ - "lazy_static", "log", + "once_cell", "tracing-core", ] @@ -4526,7 +4496,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.18", + "rustix 0.38.21", ] [[package]] @@ -4561,10 +4531,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ "windows-targets 0.48.5", ] @@ -4703,9 +4673,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.16" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" dependencies = [ "memchr", ] @@ -4805,6 +4775,26 @@ dependencies = [ "zvariant", ] +[[package]] +name = "zerocopy" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c552e97c5a9b90bc8ddc545b5106e798807376356688ebaa3aee36f44f8c4b9e" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "964bc0588d7ac1c0243d0427ef08482618313702bbb014806cb7ab3da34d3d99" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "zeroize" version = "1.3.0" diff --git a/Cargo.toml b/Cargo.toml index 28d8763cb..319a55708 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,11 @@ near-jsonrpc-primitives = "0.17.0" near-gas = { version = "0.2.3", features = [ "serde", "borsh", - "schemars", + "interactive-clap", +] } +near-token = { version = "0.2.0", features = [ + "serde", + "borsh", "interactive-clap", ] } @@ -79,7 +83,7 @@ keyring = "2.0.5" interactive-clap = "0.2.7" interactive-clap-derive = "0.2.7" -near-socialdb-client = "0.1.0" +near-socialdb-client = "0.2.1" [features] default = ["ledger", "self-update"] diff --git a/src/commands/account/add_key/access_key_type/mod.rs b/src/commands/account/add_key/access_key_type/mod.rs index 9491d8224..ead451463 100644 --- a/src/commands/account/add_key/access_key_type/mod.rs +++ b/src/commands/account/add_key/access_key_type/mod.rs @@ -54,7 +54,7 @@ impl From for AccessTypeContext { pub struct FunctionCallType { #[interactive_clap(long)] #[interactive_clap(skip_default_input_arg)] - allowance: Option, + allowance: Option, #[interactive_clap(long)] /// Enter a receiver to use by this access key to pay for function call gas and transaction fees: receiver_account_id: crate::types::account_id::AccountId, @@ -69,7 +69,7 @@ pub struct FunctionCallType { pub struct FunctionCallTypeContext { global_context: crate::GlobalContext, signer_account_id: near_primitives::types::AccountId, - allowance: Option, + allowance: Option, receiver_account_id: crate::types::account_id::AccountId, method_names: crate::types::vec_string::VecString, } @@ -82,7 +82,7 @@ impl FunctionCallTypeContext { Ok(Self { global_context: previous_context.global_context, signer_account_id: previous_context.owner_account_id.into(), - allowance: scope.allowance.clone(), + allowance: scope.allowance, receiver_account_id: scope.receiver_account_id.clone(), method_names: scope.method_names.clone(), }) @@ -96,7 +96,7 @@ impl From for AccessTypeContext { signer_account_id: item.signer_account_id, permission: near_primitives::account::AccessKeyPermission::FunctionCall( near_primitives::account::FunctionCallPermission { - allowance: item.allowance.map(|allowance| allowance.to_yoctonear()), + allowance: item.allowance.map(|allowance| allowance.as_yoctonear()), receiver_id: item.receiver_account_id.to_string(), method_names: item.method_names.into(), }, @@ -126,7 +126,7 @@ impl interactive_clap::FromCli for FunctionCallType { Err(err) => return interactive_clap::ResultFromCli::Err(Some(clap_variant), err), }; } - let allowance = clap_variant.allowance.clone(); + let allowance = clap_variant.allowance; if clap_variant.receiver_account_id.is_none() { clap_variant.receiver_account_id = match Self::input_receiver_account_id(&context) { Ok(Some(first_receiver_account_id)) => Some(first_receiver_account_id), @@ -217,7 +217,7 @@ impl FunctionCallType { pub fn input_allowance( _context: &super::AddKeyCommandContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); #[derive(strum_macros::Display)] enum ConfirmOptions { @@ -232,7 +232,7 @@ impl FunctionCallType { ) .prompt()?; if let ConfirmOptions::Yes = select_choose_input { - let allowance_near_balance: crate::common::NearBalance = + let allowance_near_balance: near_token::NearToken = CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):") .prompt()?; Ok(Some(allowance_near_balance)) diff --git a/src/commands/account/create_account/fund_myself_create_account/mod.rs b/src/commands/account/create_account/fund_myself_create_account/mod.rs index 0059ce930..76b93249c 100644 --- a/src/commands/account/create_account/fund_myself_create_account/mod.rs +++ b/src/commands/account/create_account/fund_myself_create_account/mod.rs @@ -16,7 +16,7 @@ pub struct NewAccount { new_account_id: crate::types::account_id::AccountId, #[interactive_clap(skip_default_input_arg)] /// Enter the amount for the account: - initial_balance: crate::common::NearBalance, + initial_balance: near_token::NearToken, #[interactive_clap(subcommand)] access_key_mode: add_key::AccessKeyMode, } @@ -25,7 +25,7 @@ pub struct NewAccount { pub struct NewAccountContext { global_context: crate::GlobalContext, new_account_id: near_primitives::types::AccountId, - initial_balance: crate::common::NearBalance, + initial_balance: near_token::NearToken, } impl NewAccountContext { @@ -36,7 +36,7 @@ impl NewAccountContext { Ok(Self { global_context: previous_context, new_account_id: scope.new_account_id.clone().into(), - initial_balance: scope.initial_balance.clone(), + initial_balance: scope.initial_balance, }) } } @@ -130,9 +130,9 @@ impl NewAccount { fn input_initial_balance( _context: &crate::GlobalContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str(&Text::new("Enter the amount of the NEAR tokens you want to fund the new account with (example: 10NEAR or 0.5near or 10000yoctonear):") + match near_token::NearToken::from_str(&Text::new("Enter the amount of the NEAR tokens you want to fund the new account with (example: 10NEAR or 0.5near or 10000yoctonear):") .with_initial_value("0.1 NEAR") .prompt()? ) { @@ -156,5 +156,5 @@ pub struct AccountPropertiesContext { pub struct AccountProperties { pub new_account_id: near_primitives::types::AccountId, pub public_key: near_crypto::PublicKey, - pub initial_balance: crate::common::NearBalance, + pub initial_balance: near_token::NearToken, } diff --git a/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs b/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs index 293236aee..64442d9d3 100644 --- a/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs +++ b/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs @@ -65,7 +65,7 @@ impl From for crate::commands::ActionContext { ), near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: item.account_properties.initial_balance.to_yoctonear(), + deposit: item.account_properties.initial_balance.as_yoctonear(), }, ), near_primitives::transaction::Action::AddKey( @@ -101,7 +101,7 @@ impl From for crate::commands::ActionContext { deposit: item .account_properties .initial_balance - .to_yoctonear(), + .as_yoctonear(), }, )], linkdrop_account_id.clone(), diff --git a/src/commands/account/storage_management/storage_deposit.rs b/src/commands/account/storage_management/storage_deposit.rs index 816ae34bb..e2cb82dbf 100644 --- a/src/commands/account/storage_management/storage_deposit.rs +++ b/src/commands/account/storage_management/storage_deposit.rs @@ -8,7 +8,7 @@ pub struct DepositArgs { /// Which account ID do you want to add a deposit to? receiver_account_id: crate::types::account_id::AccountId, /// Enter the amount to deposit into the storage (example: 10NEAR or 0.5near or 10000yoctonear): - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(named_arg)] /// What is the signer account ID? sign_as: SignerAccountId, @@ -19,7 +19,7 @@ pub struct DepositArgsContext { global_context: crate::GlobalContext, get_contract_account_id: super::GetContractAccountId, receiver_account_id: near_primitives::types::AccountId, - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, } impl DepositArgsContext { @@ -31,7 +31,7 @@ impl DepositArgsContext { global_context: previous_context.global_context, get_contract_account_id: previous_context.get_contract_account_id, receiver_account_id: scope.receiver_account_id.clone().into(), - deposit: scope.deposit.clone(), + deposit: scope.deposit, }) } } @@ -108,7 +108,7 @@ impl SignerAccountIdContext { scope.signer_account_id.clone().into(); let receiver_account_id = previous_context.receiver_account_id.clone(); let get_contract_account_id = previous_context.get_contract_account_id.clone(); - let deposit = previous_context.deposit.clone(); + let deposit = previous_context.deposit; move |network_config| { Ok(crate::commands::PrepopulatedTransaction { @@ -121,7 +121,7 @@ impl SignerAccountIdContext { .to_string() .into_bytes(), gas: crate::common::NearGas::from_tgas(50).as_gas(), - deposit: deposit.to_yoctonear(), + deposit: deposit.as_yoctonear(), }, )], }) diff --git a/src/commands/account/storage_management/storage_withdraw.rs b/src/commands/account/storage_management/storage_withdraw.rs index 00d3d5f01..ae666e2b0 100644 --- a/src/commands/account/storage_management/storage_withdraw.rs +++ b/src/commands/account/storage_management/storage_withdraw.rs @@ -3,7 +3,7 @@ #[interactive_clap(output_context = WithdrawArgsContext)] pub struct WithdrawArgs { /// Enter the amount to withdraw from the storage (example: 10NEAR or 0.5near or 10000yoctonear): - amount: crate::common::NearBalance, + amount: near_token::NearToken, #[interactive_clap(named_arg)] /// What is the signer account ID? sign_as: SignerAccountId, @@ -13,7 +13,7 @@ pub struct WithdrawArgs { pub struct WithdrawArgsContext { global_context: crate::GlobalContext, get_contract_account_id: super::GetContractAccountId, - amount: crate::common::NearBalance, + amount: near_token::NearToken, } impl WithdrawArgsContext { @@ -24,7 +24,7 @@ impl WithdrawArgsContext { Ok(Self { global_context: previous_context.global_context, get_contract_account_id: previous_context.get_contract_account_id, - amount: scope.amount.clone(), + amount: scope.amount, }) } } @@ -54,7 +54,7 @@ impl SignerAccountIdContext { let signer_account_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let get_contract_account_id = previous_context.get_contract_account_id.clone(); - let amount = previous_context.amount.clone(); + let amount = previous_context.amount; move |network_config| { Ok(crate::commands::PrepopulatedTransaction { @@ -64,13 +64,12 @@ impl SignerAccountIdContext { near_primitives::transaction::FunctionCallAction { method_name: "storage_withdraw".to_string(), args: serde_json::json!({ - "amount": amount.clone().to_yoctonear().to_string() + "amount": amount.clone().as_yoctonear().to_string() }) .to_string() .into_bytes(), gas: crate::common::NearGas::from_tgas(50).as_gas(), - deposit: crate::common::NearBalance::from_yoctonear(1) - .to_yoctonear(), + deposit: near_token::NearToken::from_yoctonear(1).as_yoctonear(), }, )], }) diff --git a/src/commands/account/storage_management/view_storage_balance.rs b/src/commands/account/storage_management/view_storage_balance.rs index 6bb36e1d1..f6d75627d 100644 --- a/src/commands/account/storage_management/view_storage_balance.rs +++ b/src/commands/account/storage_management/view_storage_balance.rs @@ -53,13 +53,13 @@ impl AccountContext { eprintln!(" {:<13} {:>10} ({} [{:>28} yoctoNEAR])", "available:", bytesize::ByteSize(u64::try_from(storage_balance.available / STORAGE_COST_PER_BYTE).unwrap()), - crate::common::NearBalance::from_yoctonear(storage_balance.available), + near_token::NearToken::from_yoctonear(storage_balance.available), storage_balance.available ); eprintln!(" {:<13} {:>10} ({} [{:>28} yoctoNEAR])", "total:", bytesize::ByteSize(u64::try_from(storage_balance.total / STORAGE_COST_PER_BYTE).unwrap()), - crate::common::NearBalance::from_yoctonear(storage_balance.total), + near_token::NearToken::from_yoctonear(storage_balance.total), storage_balance.total ); diff --git a/src/commands/account/update_social_profile/sign_as.rs b/src/commands/account/update_social_profile/sign_as.rs index c89dce9d0..1629d4711 100644 --- a/src/commands/account/update_social_profile/sign_as.rs +++ b/src/commands/account/update_social_profile/sign_as.rs @@ -113,7 +113,7 @@ impl From for crate::commands::ActionContext { method_name: "set".to_string(), args, gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: deposit.to_yoctonear(), + deposit: deposit.as_yoctonear(), }, )]; @@ -139,9 +139,9 @@ impl From for crate::commands::ActionContext { &account_id, "profile", &prepopulated_unsigned_transaction.receiver_id, - crate::common::NearBalance::from_yoctonear(action.deposit), + near_token::NearToken::from_yoctonear(action.deposit), ))? - .to_yoctonear(); + .as_yoctonear(); Ok(()) } else { color_eyre::eyre::bail!("Unexpected action to change components",); diff --git a/src/commands/contract/call_function/as_transaction/mod.rs b/src/commands/contract/call_function/as_transaction/mod.rs index 5a9e6db50..294cab675 100644 --- a/src/commands/contract/call_function/as_transaction/mod.rs +++ b/src/commands/contract/call_function/as_transaction/mod.rs @@ -132,7 +132,7 @@ impl PrepaidGas { pub struct Deposit { #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(named_arg)] /// What is the signer account ID? sign_as: SignerAccountId, @@ -145,7 +145,7 @@ pub struct DepositContext { function_name: String, function_args: Vec, gas: crate::common::NearGas, - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, } impl DepositContext { @@ -159,7 +159,7 @@ impl DepositContext { function_name: previous_context.function_name, function_args: previous_context.function_args, gas: previous_context.gas, - deposit: scope.deposit.clone(), + deposit: scope.deposit, }) } } @@ -167,9 +167,9 @@ impl DepositContext { impl Deposit { fn input_deposit( _context: &PrepaidGasContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) @@ -201,7 +201,7 @@ pub struct SignerAccountIdContext { function_name: String, function_args: Vec, gas: crate::common::NearGas, - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, signer_account_id: near_primitives::types::AccountId, } @@ -238,7 +238,7 @@ impl From for crate::commands::ActionContext { method_name: item.function_name.clone(), args: item.function_args.clone(), gas: item.gas.as_gas(), - deposit: item.deposit.to_yoctonear(), + deposit: item.deposit.as_yoctonear(), }, )], }) diff --git a/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs b/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs index 494bf6fdc..143a10af1 100644 --- a/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs +++ b/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs @@ -132,7 +132,7 @@ impl PrepaidGas { pub struct Deposit { #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -146,7 +146,7 @@ impl DepositContext { previous_context: PrepaidGasContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let deposit = scope.deposit.clone(); + let deposit = scope.deposit; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ @@ -168,7 +168,7 @@ impl DepositContext { method_name: previous_context.function_name.clone(), args: previous_context.function_args.clone(), gas: previous_context.gas.as_gas(), - deposit: deposit.to_yoctonear(), + deposit: deposit.as_yoctonear(), }, ), ], @@ -205,9 +205,9 @@ impl From for crate::commands::ActionContext { impl Deposit { fn input_deposit( _context: &PrepaidGasContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) diff --git a/src/commands/tokens/send_ft/mod.rs b/src/commands/tokens/send_ft/mod.rs index 10724e31b..bcc7b78ee 100644 --- a/src/commands/tokens/send_ft/mod.rs +++ b/src/commands/tokens/send_ft/mod.rs @@ -22,7 +22,7 @@ pub struct SendFtCommand { #[interactive_clap(long = "attached-deposit")] #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -36,7 +36,7 @@ pub struct SendFtCommandContext { receiver_account_id: near_primitives::types::AccountId, amount: u128, gas: crate::common::NearGas, - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, } impl SendFtCommandContext { @@ -51,7 +51,7 @@ impl SendFtCommandContext { receiver_account_id: scope.receiver_account_id.clone().into(), amount: scope.amount, gas: scope.gas, - deposit: scope.deposit.clone(), + deposit: scope.deposit, }) } } @@ -78,7 +78,7 @@ impl From for crate::commands::ActionContext { .to_string() .into_bytes(), gas: item.gas.as_gas(), - deposit: item.deposit.to_yoctonear(), + deposit: item.deposit.as_yoctonear(), }, )], }) @@ -164,9 +164,9 @@ impl SendFtCommand { fn input_deposit( _context: &super::TokensCommandsContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) diff --git a/src/commands/tokens/send_near/mod.rs b/src/commands/tokens/send_near/mod.rs index 96568142b..7393968cd 100644 --- a/src/commands/tokens/send_near/mod.rs +++ b/src/commands/tokens/send_near/mod.rs @@ -9,7 +9,7 @@ pub struct SendNearCommand { receiver_account_id: crate::types::account_id::AccountId, #[interactive_clap(skip_default_input_arg)] /// Enter an amount to transfer: - amount_in_near: crate::common::NearBalance, + amount_in_near: near_token::NearToken, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -20,7 +20,7 @@ pub struct SendNearCommandContext { global_context: crate::GlobalContext, signer_account_id: near_primitives::types::AccountId, receiver_account_id: near_primitives::types::AccountId, - amount_in_near: crate::common::NearBalance, + amount_in_near: near_token::NearToken, } impl SendNearCommandContext { @@ -32,7 +32,7 @@ impl SendNearCommandContext { global_context: previous_context.global_context, signer_account_id: previous_context.owner_account_id, receiver_account_id: scope.receiver_account_id.clone().into(), - amount_in_near: scope.amount_in_near.clone(), + amount_in_near: scope.amount_in_near, }) } } @@ -50,7 +50,7 @@ impl From for crate::commands::ActionContext { receiver_id: receiver_account_id.clone(), actions: vec![near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: item.amount_in_near.to_yoctonear(), + deposit: item.amount_in_near.as_yoctonear(), }, )], }) @@ -86,7 +86,7 @@ impl SendNearCommand { fn input_amount_in_near( _context: &super::TokensCommandsContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { let input_amount = CustomType::new("How many NEAR Tokens do you want to transfer? (example: 10NEAR or 0.5near or 10000yoctonear)").prompt()?; Ok(Some(input_amount)) diff --git a/src/commands/tokens/send_nft/mod.rs b/src/commands/tokens/send_nft/mod.rs index c53c85823..88d0986fe 100644 --- a/src/commands/tokens/send_nft/mod.rs +++ b/src/commands/tokens/send_nft/mod.rs @@ -22,7 +22,7 @@ pub struct SendNftCommand { #[interactive_clap(long = "attached-deposit")] #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -36,7 +36,7 @@ pub struct SendNftCommandContext { receiver_account_id: near_primitives::types::AccountId, token_id: String, gas: crate::common::NearGas, - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, } impl SendNftCommandContext { @@ -51,7 +51,7 @@ impl SendNftCommandContext { receiver_account_id: scope.receiver_account_id.clone().into(), token_id: scope.token_id.clone(), gas: scope.gas, - deposit: scope.deposit.clone(), + deposit: scope.deposit, }) } } @@ -79,7 +79,7 @@ impl From for crate::commands::ActionContext { .to_string() .into_bytes(), gas: item.gas.as_gas(), - deposit: item.deposit.to_yoctonear(), + deposit: item.deposit.as_yoctonear(), }, )], }) @@ -165,9 +165,9 @@ impl SendNftCommand { fn input_deposit( _context: &super::TokensCommandsContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) diff --git a/src/commands/transaction/construct_transaction/add_action_1/add_action/add_key/access_key_type/mod.rs b/src/commands/transaction/construct_transaction/add_action_1/add_action/add_key/access_key_type/mod.rs index d74c93c3e..45a57d6cb 100644 --- a/src/commands/transaction/construct_transaction/add_action_1/add_action/add_key/access_key_type/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_1/add_action/add_key/access_key_type/mod.rs @@ -51,7 +51,7 @@ pub struct FunctionCallType { #[interactive_clap(long)] #[interactive_clap(skip_default_from_cli_arg)] #[interactive_clap(skip_default_input_arg)] - allowance: Option, + allowance: Option, #[interactive_clap(long)] /// Enter a receiver to use by this access key to pay for function call gas and transaction fees: receiver_account_id: crate::types::account_id::AccountId, @@ -73,10 +73,7 @@ impl FunctionCallTypeContext { ) -> color_eyre::eyre::Result { let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall( near_primitives::account::FunctionCallPermission { - allowance: scope - .allowance - .clone() - .map(|allowance| allowance.to_yoctonear()), + allowance: scope.allowance.map(|allowance| allowance.as_yoctonear()), receiver_id: scope.receiver_account_id.to_string(), method_names: scope.method_names.clone().into(), }, @@ -118,7 +115,7 @@ impl interactive_clap::FromCli for FunctionCallType { Err(err) => return interactive_clap::ResultFromCli::Err(Some(clap_variant), err), }; } - let allowance = clap_variant.allowance.clone(); + let allowance = clap_variant.allowance; if clap_variant.receiver_account_id.is_none() { clap_variant.receiver_account_id = match Self::input_receiver_account_id(&context) { Ok(Some(first_receiver_account_id)) => Some(first_receiver_account_id), @@ -208,7 +205,7 @@ impl FunctionCallType { } } - pub fn input_allowance() -> color_eyre::eyre::Result> { + pub fn input_allowance() -> color_eyre::eyre::Result> { eprintln!(); #[derive(strum_macros::Display)] enum ConfirmOptions { @@ -223,7 +220,7 @@ impl FunctionCallType { ) .prompt()?; if let ConfirmOptions::Yes = select_choose_input { - let allowance_near_balance: crate::common::NearBalance = + let allowance_near_balance: near_token::NearToken = CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):") .prompt()?; Ok(Some(allowance_near_balance)) diff --git a/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs b/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs index ba5552f55..669c5e191 100644 --- a/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs @@ -133,7 +133,7 @@ impl PrepaidGas { pub struct Deposit { #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_2::NextAction, } @@ -151,7 +151,7 @@ impl DepositContext { method_name: previous_context.function_name, args: previous_context.function_args, gas: previous_context.gas.as_gas(), - deposit: scope.deposit.clone().to_yoctonear(), + deposit: scope.deposit.clone().as_yoctonear(), }, ); let mut actions = previous_context.actions; @@ -174,9 +174,9 @@ impl From for super::super::super::ConstructTransactionContext { impl Deposit { fn input_deposit( _context: &PrepaidGasContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) diff --git a/src/commands/transaction/construct_transaction/add_action_1/add_action/stake/mod.rs b/src/commands/transaction/construct_transaction/add_action_1/add_action/stake/mod.rs index 18518f383..7bf8ddc93 100644 --- a/src/commands/transaction/construct_transaction/add_action_1/add_action/stake/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_1/add_action/stake/mod.rs @@ -2,7 +2,7 @@ #[interactive_clap(input_context = super::super::super::ConstructTransactionContext)] #[interactive_clap(output_context = StakeActionContext)] pub struct StakeAction { - stake_amount: crate::common::NearBalance, + stake_amount: near_token::NearToken, public_key: crate::types::public_key::PublicKey, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_2::NextAction, @@ -18,7 +18,7 @@ impl StakeActionContext { ) -> color_eyre::eyre::Result { let action = near_primitives::transaction::Action::Stake( near_primitives::transaction::StakeAction { - stake: scope.stake_amount.to_yoctonear(), + stake: scope.stake_amount.as_yoctonear(), public_key: scope.public_key.clone().into(), }, ); diff --git a/src/commands/transaction/construct_transaction/add_action_1/add_action/transfer/mod.rs b/src/commands/transaction/construct_transaction/add_action_1/add_action/transfer/mod.rs index d57c6ff99..8a8673915 100644 --- a/src/commands/transaction/construct_transaction/add_action_1/add_action/transfer/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_1/add_action/transfer/mod.rs @@ -3,7 +3,7 @@ #[interactive_clap(output_context = TransferActionContext)] pub struct TransferAction { /// How many NEAR Tokens do you want to transfer? (example: 10NEAR or 0.5near or 10000yoctonear) - amount_in_near: crate::common::NearBalance, + amount_in_near: near_token::NearToken, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_2::NextAction, } @@ -18,7 +18,7 @@ impl TransferActionContext { ) -> color_eyre::eyre::Result { let action = near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: scope.amount_in_near.to_yoctonear(), + deposit: scope.amount_in_near.as_yoctonear(), }, ); let mut actions = previous_context.actions; diff --git a/src/commands/transaction/construct_transaction/add_action_2/add_action/add_key/access_key_type/mod.rs b/src/commands/transaction/construct_transaction/add_action_2/add_action/add_key/access_key_type/mod.rs index d74c93c3e..45a57d6cb 100644 --- a/src/commands/transaction/construct_transaction/add_action_2/add_action/add_key/access_key_type/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_2/add_action/add_key/access_key_type/mod.rs @@ -51,7 +51,7 @@ pub struct FunctionCallType { #[interactive_clap(long)] #[interactive_clap(skip_default_from_cli_arg)] #[interactive_clap(skip_default_input_arg)] - allowance: Option, + allowance: Option, #[interactive_clap(long)] /// Enter a receiver to use by this access key to pay for function call gas and transaction fees: receiver_account_id: crate::types::account_id::AccountId, @@ -73,10 +73,7 @@ impl FunctionCallTypeContext { ) -> color_eyre::eyre::Result { let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall( near_primitives::account::FunctionCallPermission { - allowance: scope - .allowance - .clone() - .map(|allowance| allowance.to_yoctonear()), + allowance: scope.allowance.map(|allowance| allowance.as_yoctonear()), receiver_id: scope.receiver_account_id.to_string(), method_names: scope.method_names.clone().into(), }, @@ -118,7 +115,7 @@ impl interactive_clap::FromCli for FunctionCallType { Err(err) => return interactive_clap::ResultFromCli::Err(Some(clap_variant), err), }; } - let allowance = clap_variant.allowance.clone(); + let allowance = clap_variant.allowance; if clap_variant.receiver_account_id.is_none() { clap_variant.receiver_account_id = match Self::input_receiver_account_id(&context) { Ok(Some(first_receiver_account_id)) => Some(first_receiver_account_id), @@ -208,7 +205,7 @@ impl FunctionCallType { } } - pub fn input_allowance() -> color_eyre::eyre::Result> { + pub fn input_allowance() -> color_eyre::eyre::Result> { eprintln!(); #[derive(strum_macros::Display)] enum ConfirmOptions { @@ -223,7 +220,7 @@ impl FunctionCallType { ) .prompt()?; if let ConfirmOptions::Yes = select_choose_input { - let allowance_near_balance: crate::common::NearBalance = + let allowance_near_balance: near_token::NearToken = CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):") .prompt()?; Ok(Some(allowance_near_balance)) diff --git a/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs b/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs index 43aa368bd..44d1c06f0 100644 --- a/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs @@ -133,7 +133,7 @@ impl PrepaidGas { pub struct Deposit { #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_3::NextAction, } @@ -151,7 +151,7 @@ impl DepositContext { method_name: previous_context.function_name, args: previous_context.function_args, gas: previous_context.gas.as_gas(), - deposit: scope.deposit.clone().to_yoctonear(), + deposit: scope.deposit.clone().as_yoctonear(), }, ); let mut actions = previous_context.actions; @@ -174,9 +174,9 @@ impl From for super::super::super::ConstructTransactionContext { impl Deposit { fn input_deposit( _context: &PrepaidGasContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) diff --git a/src/commands/transaction/construct_transaction/add_action_2/add_action/stake/mod.rs b/src/commands/transaction/construct_transaction/add_action_2/add_action/stake/mod.rs index 34f248ada..91dce2489 100644 --- a/src/commands/transaction/construct_transaction/add_action_2/add_action/stake/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_2/add_action/stake/mod.rs @@ -2,7 +2,7 @@ #[interactive_clap(input_context = super::super::super::ConstructTransactionContext)] #[interactive_clap(output_context = StakeActionContext)] pub struct StakeAction { - stake_amount: crate::common::NearBalance, + stake_amount: near_token::NearToken, public_key: crate::types::public_key::PublicKey, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_3::NextAction, @@ -18,7 +18,7 @@ impl StakeActionContext { ) -> color_eyre::eyre::Result { let action = near_primitives::transaction::Action::Stake( near_primitives::transaction::StakeAction { - stake: scope.stake_amount.to_yoctonear(), + stake: scope.stake_amount.as_yoctonear(), public_key: scope.public_key.clone().into(), }, ); diff --git a/src/commands/transaction/construct_transaction/add_action_2/add_action/transfer/mod.rs b/src/commands/transaction/construct_transaction/add_action_2/add_action/transfer/mod.rs index 855e0d91a..89be419eb 100644 --- a/src/commands/transaction/construct_transaction/add_action_2/add_action/transfer/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_2/add_action/transfer/mod.rs @@ -3,7 +3,7 @@ #[interactive_clap(output_context = TransferActionContext)] pub struct TransferAction { /// How many NEAR Tokens do you want to transfer? (example: 10NEAR or 0.5near or 10000yoctonear) - amount_in_near: crate::common::NearBalance, + amount_in_near: near_token::NearToken, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_3::NextAction, } @@ -18,7 +18,7 @@ impl TransferActionContext { ) -> color_eyre::eyre::Result { let action = near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: scope.amount_in_near.to_yoctonear(), + deposit: scope.amount_in_near.as_yoctonear(), }, ); let mut actions = previous_context.actions; diff --git a/src/commands/transaction/construct_transaction/add_action_3/add_action/add_key/access_key_type/mod.rs b/src/commands/transaction/construct_transaction/add_action_3/add_action/add_key/access_key_type/mod.rs index d74c93c3e..45a57d6cb 100644 --- a/src/commands/transaction/construct_transaction/add_action_3/add_action/add_key/access_key_type/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_3/add_action/add_key/access_key_type/mod.rs @@ -51,7 +51,7 @@ pub struct FunctionCallType { #[interactive_clap(long)] #[interactive_clap(skip_default_from_cli_arg)] #[interactive_clap(skip_default_input_arg)] - allowance: Option, + allowance: Option, #[interactive_clap(long)] /// Enter a receiver to use by this access key to pay for function call gas and transaction fees: receiver_account_id: crate::types::account_id::AccountId, @@ -73,10 +73,7 @@ impl FunctionCallTypeContext { ) -> color_eyre::eyre::Result { let access_key_permission = near_primitives::account::AccessKeyPermission::FunctionCall( near_primitives::account::FunctionCallPermission { - allowance: scope - .allowance - .clone() - .map(|allowance| allowance.to_yoctonear()), + allowance: scope.allowance.map(|allowance| allowance.as_yoctonear()), receiver_id: scope.receiver_account_id.to_string(), method_names: scope.method_names.clone().into(), }, @@ -118,7 +115,7 @@ impl interactive_clap::FromCli for FunctionCallType { Err(err) => return interactive_clap::ResultFromCli::Err(Some(clap_variant), err), }; } - let allowance = clap_variant.allowance.clone(); + let allowance = clap_variant.allowance; if clap_variant.receiver_account_id.is_none() { clap_variant.receiver_account_id = match Self::input_receiver_account_id(&context) { Ok(Some(first_receiver_account_id)) => Some(first_receiver_account_id), @@ -208,7 +205,7 @@ impl FunctionCallType { } } - pub fn input_allowance() -> color_eyre::eyre::Result> { + pub fn input_allowance() -> color_eyre::eyre::Result> { eprintln!(); #[derive(strum_macros::Display)] enum ConfirmOptions { @@ -223,7 +220,7 @@ impl FunctionCallType { ) .prompt()?; if let ConfirmOptions::Yes = select_choose_input { - let allowance_near_balance: crate::common::NearBalance = + let allowance_near_balance: near_token::NearToken = CustomType::new("Enter an allowance which is a balance limit to use by this access key to pay for function call gas and transaction fees (example: 10NEAR or 0.5near or 10000yoctonear):") .prompt()?; Ok(Some(allowance_near_balance)) diff --git a/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs b/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs index cf4fce49c..4a918afc8 100644 --- a/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs @@ -133,7 +133,7 @@ impl PrepaidGas { pub struct Deposit { #[interactive_clap(skip_default_input_arg)] /// Enter deposit for a function call: - deposit: crate::common::NearBalance, + deposit: near_token::NearToken, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_last::NextAction, } @@ -151,7 +151,7 @@ impl DepositContext { method_name: previous_context.function_name, args: previous_context.function_args, gas: previous_context.gas.as_gas(), - deposit: scope.deposit.clone().to_yoctonear(), + deposit: scope.deposit.clone().as_yoctonear(), }, ); let mut actions = previous_context.actions; @@ -174,9 +174,9 @@ impl From for super::super::super::ConstructTransactionContext { impl Deposit { fn input_deposit( _context: &PrepaidGasContext, - ) -> color_eyre::eyre::Result> { + ) -> color_eyre::eyre::Result> { eprintln!(); - match crate::common::NearBalance::from_str( + match near_token::NearToken::from_str( &Text::new( "Enter deposit for a function call (example: 10NEAR or 0.5near or 10000yoctonear):", ) diff --git a/src/commands/transaction/construct_transaction/add_action_3/add_action/stake/mod.rs b/src/commands/transaction/construct_transaction/add_action_3/add_action/stake/mod.rs index 5f7a98137..9cdac2259 100644 --- a/src/commands/transaction/construct_transaction/add_action_3/add_action/stake/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_3/add_action/stake/mod.rs @@ -2,7 +2,7 @@ #[interactive_clap(input_context = super::super::super::ConstructTransactionContext)] #[interactive_clap(output_context = StakeActionContext)] pub struct StakeAction { - stake_amount: crate::common::NearBalance, + stake_amount: near_token::NearToken, public_key: crate::types::public_key::PublicKey, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_last::NextAction, @@ -18,7 +18,7 @@ impl StakeActionContext { ) -> color_eyre::eyre::Result { let action = near_primitives::transaction::Action::Stake( near_primitives::transaction::StakeAction { - stake: scope.stake_amount.to_yoctonear(), + stake: scope.stake_amount.as_yoctonear(), public_key: scope.public_key.clone().into(), }, ); diff --git a/src/commands/transaction/construct_transaction/add_action_3/add_action/transfer/mod.rs b/src/commands/transaction/construct_transaction/add_action_3/add_action/transfer/mod.rs index 0547c0965..eb08add3e 100644 --- a/src/commands/transaction/construct_transaction/add_action_3/add_action/transfer/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_3/add_action/transfer/mod.rs @@ -3,7 +3,7 @@ #[interactive_clap(output_context = TransferActionContext)] pub struct TransferAction { /// How many NEAR Tokens do you want to transfer? (example: 10NEAR or 0.5near or 10000yoctonear) - amount_in_near: crate::common::NearBalance, + amount_in_near: near_token::NearToken, #[interactive_clap(subcommand)] next_action: super::super::super::add_action_last::NextAction, } @@ -18,7 +18,7 @@ impl TransferActionContext { ) -> color_eyre::eyre::Result { let action = near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: scope.amount_in_near.to_yoctonear(), + deposit: scope.amount_in_near.as_yoctonear(), }, ); let mut actions = previous_context.actions; diff --git a/src/common.rs b/src/common.rs index 45b125b8e..58fa9632b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -68,17 +68,15 @@ impl std::fmt::Display for BlockHashAsBase58 { } } -pub use near_socialdb_client::NearBalance; - pub use near_gas::NearGas; #[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd)] pub struct TransferAmount { - amount: NearBalance, + amount: near_token::NearToken, } impl interactive_clap::ToCli for TransferAmount { - type CliVariant = NearBalance; + type CliVariant = near_token::NearToken; } impl std::fmt::Display for TransferAmount { @@ -89,7 +87,7 @@ impl std::fmt::Display for TransferAmount { impl TransferAmount { pub fn from( - amount: NearBalance, + amount: near_token::NearToken, account_transfer_allowance: &AccountTransferAllowance, ) -> color_eyre::eyre::Result { if amount <= account_transfer_allowance.transfer_allowance() { @@ -101,16 +99,16 @@ impl TransferAmount { } } - pub fn from_unchecked(amount: NearBalance) -> Self { + pub fn from_unchecked(amount: near_token::NearToken) -> Self { Self { amount } } - pub fn to_yoctonear(&self) -> u128 { - self.amount.to_yoctonear() + pub fn as_yoctonear(&self) -> u128 { + self.amount.as_yoctonear() } } -impl From for NearBalance { +impl From for near_token::NearToken { fn from(item: TransferAmount) -> Self { item.amount } @@ -119,10 +117,10 @@ impl From for NearBalance { #[derive(Debug)] pub struct AccountTransferAllowance { account_id: near_primitives::types::AccountId, - account_liquid_balance: NearBalance, - account_locked_balance: NearBalance, - storage_stake: NearBalance, - pessimistic_transaction_fee: NearBalance, + account_liquid_balance: near_token::NearToken, + account_locked_balance: near_token::NearToken, + storage_stake: near_token::NearToken, + pessimistic_transaction_fee: near_token::NearToken, } impl std::fmt::Display for AccountTransferAllowance { @@ -139,20 +137,15 @@ impl std::fmt::Display for AccountTransferAllowance { } impl AccountTransferAllowance { - pub fn liquid_storage_stake(&self) -> NearBalance { - NearBalance::from_yoctonear( - self.storage_stake - .to_yoctonear() - .saturating_sub(self.account_locked_balance.to_yoctonear()), - ) + pub fn liquid_storage_stake(&self) -> near_token::NearToken { + self.storage_stake + .saturating_sub(self.account_locked_balance) } - pub fn transfer_allowance(&self) -> NearBalance { - NearBalance::from_yoctonear( - self.account_liquid_balance.to_yoctonear() - - self.liquid_storage_stake().to_yoctonear() - - self.pessimistic_transaction_fee.to_yoctonear(), - ) + pub fn transfer_allowance(&self) -> near_token::NearToken { + self.account_liquid_balance + .saturating_sub(self.liquid_storage_stake()) + .saturating_sub(self.pessimistic_transaction_fee) } } @@ -168,10 +161,10 @@ pub fn get_account_transfer_allowance( } else { return Ok(AccountTransferAllowance { account_id, - account_liquid_balance: NearBalance::from_yoctonear(0), - account_locked_balance: NearBalance::from_yoctonear(0), - storage_stake: NearBalance::from_yoctonear(0), - pessimistic_transaction_fee: NearBalance::from_yoctonear(0), + account_liquid_balance: near_token::NearToken::from_near(0), + account_locked_balance: near_token::NearToken::from_near(0), + storage_stake: near_token::NearToken::from_near(0), + pessimistic_transaction_fee: near_token::NearToken::from_near(0), }); }; let storage_amount_per_byte = tokio::runtime::Runtime::new() @@ -187,15 +180,15 @@ pub fn get_account_transfer_allowance( Ok(AccountTransferAllowance { account_id, - account_liquid_balance: NearBalance::from_yoctonear(account_view.amount), - account_locked_balance: NearBalance::from_yoctonear(account_view.locked), - storage_stake: NearBalance::from_yoctonear( + account_liquid_balance: near_token::NearToken::from_yoctonear(account_view.amount), + account_locked_balance: near_token::NearToken::from_yoctonear(account_view.locked), + storage_stake: near_token::NearToken::from_yoctonear( u128::from(account_view.storage_usage) * storage_amount_per_byte, ), // pessimistic_transaction_fee = 10^21 - this value is set temporarily // In the future, its value will be calculated by the function: fn tx_cost(...) // https://github.com/near/nearcore/blob/8a377fda0b4ce319385c463f1ae46e4b0b29dcd9/runtime/runtime/src/config.rs#L178-L232 - pessimistic_transaction_fee: NearBalance::from_yoctonear(10u128.pow(21)), + pessimistic_transaction_fee: near_token::NearToken::from_millinear(1), }) } @@ -581,7 +574,7 @@ pub fn print_unsigned_transaction(transaction: &crate::commands::PrepopulatedTra "{:>18} {:<13} {}", "", "deposit:", - NearBalance::from_yoctonear(function_call_action.deposit) + near_token::NearToken::from_yoctonear(function_call_action.deposit) ); } near_primitives::transaction::Action::Transfer(transfer_action) => { @@ -589,7 +582,7 @@ pub fn print_unsigned_transaction(transaction: &crate::commands::PrepopulatedTra "{:>5} {:<20} {}", "--", "transfer deposit:", - NearBalance::from_yoctonear(transfer_action.deposit) + near_token::NearToken::from_yoctonear(transfer_action.deposit) ); } near_primitives::transaction::Action::Stake(stake_action) => { @@ -602,7 +595,7 @@ pub fn print_unsigned_transaction(transaction: &crate::commands::PrepopulatedTra "{:>18} {:<13} {}", "", "stake:", - NearBalance::from_yoctonear(stake_action.stake) + near_token::NearToken::from_yoctonear(stake_action.stake) ); } near_primitives::transaction::Action::AddKey(add_key_action) => { @@ -680,7 +673,7 @@ fn print_value_successful_transaction( eprintln!( "<{}> has transferred {} to <{}> successfully.", transaction_info.transaction.signer_id, - NearBalance::from_yoctonear(deposit), + near_token::NearToken::from_yoctonear(deposit), transaction_info.transaction.receiver_id, ); } @@ -691,7 +684,7 @@ fn print_value_successful_transaction( eprintln!( "Validator <{}> has successfully staked {}.", transaction_info.transaction.signer_id, - NearBalance::from_yoctonear(stake), + near_token::NearToken::from_yoctonear(stake), ); } near_primitives::views::ActionView::AddKey { @@ -840,7 +833,7 @@ pub fn print_action_error(action_error: &near_primitives::errors::ActionError) - near_primitives::errors::ActionErrorKind::LackBalanceForState { account_id, amount } => { color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Receipt action can't be completed, because the remaining balance will not be enough to cover storage.\nAn account which needs balance: <{}>\nBalance required to complete the action: <{}>", account_id, - NearBalance::from_yoctonear(*amount) + near_token::NearToken::from_yoctonear(*amount) )) } near_primitives::errors::ActionErrorKind::TriesToUnstake { account_id } => { @@ -858,8 +851,8 @@ pub fn print_action_error(action_error: &near_primitives::errors::ActionError) - color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!( "Error: Account <{}> doesn't have enough balance ({}) to increase the stake ({}).", account_id, - NearBalance::from_yoctonear(*balance), - NearBalance::from_yoctonear(*stake) + near_token::NearToken::from_yoctonear(*balance), + near_token::NearToken::from_yoctonear(*stake) )) } near_primitives::errors::ActionErrorKind::InsufficientStake { @@ -869,8 +862,8 @@ pub fn print_action_error(action_error: &near_primitives::errors::ActionError) - } => { color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!( "Error: Insufficient stake {}.\nThe minimum rate must be {}.", - NearBalance::from_yoctonear(*stake), - NearBalance::from_yoctonear(*minimum_stake) + near_token::NearToken::from_yoctonear(*stake), + near_token::NearToken::from_yoctonear(*minimum_stake) )) } near_primitives::errors::ActionErrorKind::FunctionCallError(function_call_error_ser) => { @@ -944,8 +937,8 @@ pub fn handler_invalid_tx_error( color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Access Key <{}> for account <{}> does not have enough allowance ({}) to cover transaction cost ({}).", public_key, account_id, - NearBalance::from_yoctonear(*allowance), - NearBalance::from_yoctonear(*cost) + near_token::NearToken::from_yoctonear(*allowance), + near_token::NearToken::from_yoctonear(*cost) )) }, near_primitives::errors::InvalidAccessKeyError::DepositWithFunctionCall => { @@ -974,14 +967,14 @@ pub fn handler_invalid_tx_error( near_primitives::errors::InvalidTxError::NotEnoughBalance {signer_id, balance, cost} => { color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Account <{}> does not have enough balance ({}) to cover TX cost ({}).", signer_id, - NearBalance::from_yoctonear(*balance), - NearBalance::from_yoctonear(*cost) + near_token::NearToken::from_yoctonear(*balance), + near_token::NearToken::from_yoctonear(*cost) )) }, near_primitives::errors::InvalidTxError::LackBalanceForState {signer_id, amount} => { color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("Error: Signer account <{}> doesn't have enough balance ({}) after transaction.", signer_id, - NearBalance::from_yoctonear(*amount) + near_token::NearToken::from_yoctonear(*amount) )) }, near_primitives::errors::InvalidTxError::CostOverflow => { @@ -1297,11 +1290,11 @@ pub fn display_account_info( table.add_row(prettytable::row![ Fg->"Native account balance", - Fy->NearBalance::from_yoctonear(account_view.amount) + Fy->near_token::NearToken::from_yoctonear(account_view.amount) ]); table.add_row(prettytable::row![ Fg->"Validator stake", - Fy->NearBalance::from_yoctonear(account_view.locked) + Fy->near_token::NearToken::from_yoctonear(account_view.locked) ]); table.add_row(prettytable::row![ Fg->"Storage used by the account", @@ -1470,7 +1463,7 @@ pub fn display_access_key_list(access_keys: &[near_primitives::views::AccessKeyI let allowance_message = match allowance { Some(amount) => format!( "with an allowance of {}", - NearBalance::from_yoctonear(*amount) + near_token::NearToken::from_yoctonear(*amount) ), None => "with no limit".to_string(), }; @@ -1890,287 +1883,3 @@ fn input_account_id_from_used_account_list( update_used_account_list(credentials_home_dir, account_id.as_ref(), account_is_signer); Ok(Some(account_id)) } - -#[cfg(test)] -mod tests { - use super::*; - use std::str::FromStr; - - #[test] - fn near_balance_to_string_0_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 0 - } - .to_string(), - "0 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_0dot02_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 20000000000000000000000 // 23 digits - } - .to_string(), - "0.02 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_0dot1_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 100000000000000000000000 // 24 digits - } - .to_string(), - "0.1 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_0dot00001230045600789_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 12300456007890000000 // 20 digits - } - .to_string(), - "0.00001230045600789 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_10_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 10000000000000000000000000 // 26 digits - } - .to_string(), - "10 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_10dot02_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 10020000000000000000000000 // 26 digits - } - .to_string(), - "10.02 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_1yocto_near() { - let yocto_near = NearBalance::from_yoctonear(1); - assert_eq!( - yocto_near.to_string(), - "0.000000000000000000000001 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_1_yocto_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 1 - } - .to_string(), - "0.000000000000000000000001 NEAR".to_string() - ) - } - #[test] - fn near_balance_to_string_100_yocto_near() { - assert_eq!( - NearBalance { - yoctonear_amount: 100 - } - .to_string(), - "0.0000000000000000000001 NEAR".to_string() - ) - } - - #[test] - fn near_balance_from_str_currency_near() { - assert_eq!( - NearBalance::from_str("10 near").unwrap(), - NearBalance { - yoctonear_amount: 10000000000000000000000000 // 26 digits - } - ); - assert_eq!( - NearBalance::from_str("10.055NEAR").unwrap(), - NearBalance { - yoctonear_amount: 10055000000000000000000000 // 26 digits - } - ); - } - #[test] - fn near_balance_from_str_currency_n() { - assert_eq!( - NearBalance::from_str("10 n").unwrap(), - NearBalance { - yoctonear_amount: 10000000000000000000000000 // 26 digits - } - ); - assert_eq!( - NearBalance::from_str("10N ").unwrap(), - NearBalance { - yoctonear_amount: 10000000000000000000000000 // 26 digits - } - ); - } - #[test] - fn near_balance_from_str_f64_near() { - assert_eq!( - NearBalance::from_str("0.000001 near").unwrap(), - NearBalance { - yoctonear_amount: 1000000000000000000 // 18 digits - } - ); - } - #[test] - fn near_balance_from_str_0_near() { - assert_eq!( - NearBalance::from_str("0 near").unwrap(), - NearBalance { - yoctonear_amount: 0 - } - ); - } - #[test] - fn near_balance_from_str_f64_near_without_int() { - let near_balance = NearBalance::from_str(".055NEAR"); - assert_eq!( - near_balance, - Err("Near Balance: cannot parse integer from empty string".to_string()) - ); - } - #[test] - fn near_balance_from_str_05_near() { - let near_balance = NearBalance::from_str("05NEAR"); - assert_eq!( - near_balance, - Err("Near Balance: incorrect number entered".to_string()) - ); - } - #[test] - fn near_balance_from_str_currency_ynear() { - assert_eq!( - NearBalance::from_str("100 ynear").unwrap(), - NearBalance { - yoctonear_amount: 100 - } - ); - assert_eq!( - NearBalance::from_str("100YNEAR ").unwrap(), - NearBalance { - yoctonear_amount: 100 - } - ); - } - #[test] - fn near_balance_from_str_currency_yn() { - assert_eq!( - NearBalance::from_str("9000 YN ").unwrap(), - NearBalance { - yoctonear_amount: 9000 - } - ); - assert_eq!( - NearBalance::from_str("0 yn").unwrap(), - NearBalance { - yoctonear_amount: 0 - } - ); - } - #[test] - fn near_balance_from_str_currency_yoctonear() { - assert_eq!( - NearBalance::from_str("111YOCTONEAR").unwrap(), - NearBalance { - yoctonear_amount: 111 - } - ); - assert_eq!( - NearBalance::from_str("333 yoctonear").unwrap(), - NearBalance { - yoctonear_amount: 333 - } - ); - } - #[test] - fn near_balance_from_str_currency_yocton() { - assert_eq!( - NearBalance::from_str("10YOCTON").unwrap(), - NearBalance { - yoctonear_amount: 10 - } - ); - assert_eq!( - NearBalance::from_str("10 yocton ").unwrap(), - NearBalance { - yoctonear_amount: 10 - } - ); - } - #[test] - fn near_balance_from_str_f64_ynear() { - let near_balance = NearBalance::from_str("0.055yNEAR"); - assert_eq!( - near_balance, - Err("Near Balance: invalid digit found in string".to_string()) - ); - } - #[test] - fn near_balance_from_str_without_currency() { - let near_balance = NearBalance::from_str("100"); - assert_eq!( - near_balance, - Err("Near Balance: incorrect currency value entered".to_string()) - ); - } - #[test] - fn near_balance_from_str_incorrect_currency() { - let near_balance = NearBalance::from_str("100 UAH"); - assert_eq!( - near_balance, - Err("Near Balance: incorrect currency value entered".to_string()) - ); - } - #[test] - fn near_balance_from_str_invalid_double_dot() { - let near_balance = NearBalance::from_str("100.55."); - assert_eq!( - near_balance, - Err("Near Balance: incorrect currency value entered".to_string()) - ); - } - #[test] - fn near_balance_from_str_large_fractional_part() { - let near_balance = NearBalance::from_str("100.1111122222333334444455555 n"); // 25 digits after "." - assert_eq!( - near_balance, - Err("Near Balance: too large fractional part of a number".to_string()) - ); - } - #[test] - fn near_balance_from_str_large_int_part() { - let near_balance = NearBalance::from_str("1234567890123456.0 n"); - assert_eq!( - near_balance, - Err("Near Balance: underflow or overflow happens".to_string()) - ); - } - #[test] - fn near_balance_from_str_without_fractional_part() { - let near_balance = NearBalance::from_str("100. n"); - assert_eq!( - near_balance, - Err("Near Balance: cannot parse integer from empty string".to_string()) - ); - } - #[test] - fn near_balance_from_str_negative_value() { - let near_balance = NearBalance::from_str("-100 n"); - assert_eq!( - near_balance, - Err("Near Balance: invalid digit found in string".to_string()) - ); - } -}