From f937bc511ecbbefa115fb9b5eb2df70a68f69499 Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Fri, 11 Oct 2024 12:44:48 +0200 Subject: [PATCH 1/8] upgrade to near-sdk 5.5.0 --- Cargo.lock | 1011 +++++++---------------------- Cargo.toml | 2 +- README.md | 6 +- examples/fungibletoken/Cargo.toml | 4 +- examples/fungibletoken/src/lib.rs | 67 +- examples/minimumweb4/Cargo.toml | 2 +- examples/nft/Cargo.toml | 2 +- examples/purejs/Cargo.toml | 2 +- src/lib.rs | 1 + src/viewaccesscontrol.rs | 22 +- testenv/Cargo.toml | 2 +- testenv/src/testenv.rs | 16 +- 12 files changed, 328 insertions(+), 809 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a5ae9ea..4b6482f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,33 +28,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - [[package]] name = "atty" version = "0.2.14" @@ -74,15 +47,15 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" -version = "0.11.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.13.1" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bindgen" @@ -113,29 +86,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitvec" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "blake2" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" -dependencies = [ - "crypto-mac", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -160,10 +110,20 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ - "borsh-derive", + "borsh-derive 0.9.3", "hashbrown 0.11.2", ] +[[package]] +name = "borsh" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +dependencies = [ + "borsh-derive 1.5.1", + "cfg_aliases", +] + [[package]] name = "borsh-derive" version = "0.9.3" @@ -174,7 +134,21 @@ dependencies = [ "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", "proc-macro2", - "syn", + "syn 1.0.107", +] + +[[package]] +name = "borsh-derive" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +dependencies = [ + "once_cell", + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.79", + "syn_derive", ] [[package]] @@ -185,7 +159,7 @@ checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -196,7 +170,7 @@ checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -206,16 +180,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] -name = "bumpalo" -version = "3.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" - -[[package]] -name = "byte-slice-cast" -version = "1.2.2" +name = "bs58" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] [[package]] name = "byteorder" @@ -223,28 +194,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytesize" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" - -[[package]] -name = "c2-chacha" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d27dae93fe7b1e0424dc57179ac396908c26b035a87234809f5c4dfd1b47dc80" -dependencies = [ - "cipher", - "ppv-lite86", -] - -[[package]] -name = "cc" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" - [[package]] name = "cexpr" version = "0.6.0" @@ -267,29 +216,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "chrono" -version = "0.4.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-integer", - "num-traits", - "serde", - "time", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "cipher" -version = "0.2.5" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" -dependencies = [ - "generic-array", -] +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "clang-sys" @@ -311,7 +241,7 @@ dependencies = [ "atty", "bitflags", "clap_lex", - "indexmap", + "indexmap 1.9.2", "strsim", "termcolor", "textwrap", @@ -326,28 +256,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - [[package]] name = "cpufeatures" version = "0.2.5" @@ -357,12 +265,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-common" version = "0.1.6" @@ -373,16 +275,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "curve25519-dalek" version = "3.2.1" @@ -391,66 +283,43 @@ checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core 0.5.1", + "rand_core", "subtle", "zeroize", ] [[package]] -name = "cxx" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.86" +name = "darling" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn", + "darling_core", + "darling_macro", ] [[package]] -name = "cxxbridge-flags" -version = "1.0.86" +name = "darling_core" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ + "fnv", + "ident_case", "proc-macro2", "quote", - "syn", + "syn 2.0.79", ] [[package]] -name = "derive_more" -version = "0.99.17" +name = "darling_macro" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ - "convert_case", - "proc-macro2", + "darling_core", "quote", - "rustc_version", - "syn", + "syn 2.0.79", ] [[package]] @@ -478,12 +347,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9b0705efd4599c15a38151f4721f7bc388306f61084d3bfd50bd07fbca5cb60" -[[package]] -name = "easy-ext" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53aff6fdc1b181225acdcb5b14c47106726fd8e486707315b1b138baed68ee31" - [[package]] name = "ed25519" version = "1.5.2" @@ -501,7 +364,7 @@ checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek", "ed25519", - "rand 0.7.3", + "rand", "serde", "sha2 0.9.9", "zeroize", @@ -527,22 +390,16 @@ dependencies = [ ] [[package]] -name = "fixed-hash" -version = "0.7.0" +name = "equivalent" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" -dependencies = [ - "byteorder", - "rand 0.8.5", - "rustc-hex", - "static_assertions", -] +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "funty" -version = "1.1.0" +name = "fnv" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "generic-array" @@ -597,11 +454,17 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "heck" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -625,48 +488,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] -name = "iana-time-zone" -version = "0.1.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" -dependencies = [ - "cxx", - "cxx-build", -] - -[[package]] -name = "impl-codec" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443" -dependencies = [ - "parity-scale-codec", -] - -[[package]] -name = "impl-trait-for-tuples" -version = "0.2.2" +name = "ident_case" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" @@ -679,37 +504,26 @@ dependencies = [ ] [[package]] -name = "itoa" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" - -[[package]] -name = "js-sys" -version = "0.3.60" +name = "indexmap" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ - "wasm-bindgen", + "equivalent", + "hashbrown 0.15.0", ] [[package]] -name = "keccak" -version = "0.1.3" +name = "itoa" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" -dependencies = [ - "cpufeatures", -] +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] [[package]] name = "lazycell" @@ -733,15 +547,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] - [[package]] name = "log" version = "0.4.17" @@ -775,7 +580,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73" dependencies = [ - "borsh", + "borsh 0.9.3", "schemars", "semver", "serde", @@ -783,11 +588,11 @@ dependencies = [ [[package]] name = "near-account-id" -version = "0.14.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" +checksum = "35cbb989542587b47205e608324ddd391f0cee1c22b4b64ae49f458334b95907" dependencies = [ - "borsh", + "borsh 1.5.1", "serde", ] @@ -797,124 +602,64 @@ version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bacc932e79b26472797adfb21689294b6f90960d1570daaf1e0b682b59fcb35" dependencies = [ - "near-sdk", + "near-sdk 4.1.1", "schemars", "serde", "serde_json", ] [[package]] -name = "near-crypto" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" -dependencies = [ - "arrayref", - "blake2", - "borsh", - "bs58", - "c2-chacha", - "curve25519-dalek", - "derive_more", - "ed25519-dalek", - "near-account-id", - "once_cell", - "parity-secp256k1", - "primitive-types", - "rand 0.7.3", - "rand_core 0.5.1", - "serde", - "serde_json", - "subtle", - "thiserror", -] - -[[package]] -name = "near-primitives" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" -dependencies = [ - "borsh", - "byteorder", - "bytesize", - "chrono", - "derive_more", - "easy-ext", - "hex", - "near-crypto", - "near-primitives-core", - "near-rpc-error-macro", - "near-vm-errors", - "num-rational", - "once_cell", - "primitive-types", - "rand 0.7.3", - "reed-solomon-erasure", - "serde", - "serde_json", - "smart-default", - "strum", - "thiserror", -] - -[[package]] -name = "near-primitives-core" -version = "0.14.0" +name = "near-contract-standards" +version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" +checksum = "a3b985c4df43237b6ae533a6451cfa13de1f12f79f7d6254ba376f0ccd017286" dependencies = [ - "base64 0.11.0", - "borsh", - "bs58", - "derive_more", - "near-account-id", - "num-rational", - "serde", - "sha2 0.10.6", - "strum", + "near-sdk 5.5.0", ] [[package]] -name = "near-rpc-error-core" -version = "0.14.0" +name = "near-gas" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ee0b41c75ef859c193a8ff1dadfa0c8207bc0ac447cc22259721ad769a1408" +checksum = "180edcc7dc2fac41f93570d0c7b759c1b6d492f6ad093d749d644a40b4310a97" dependencies = [ - "quote", + "borsh 1.5.1", "serde", - "syn", ] [[package]] -name = "near-rpc-error-macro" -version = "0.14.0" +name = "near-sdk" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e837bd4bacd807073ec5ceb85708da7f721b46a4c2a978de86027fb0034ce31" +checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" dependencies = [ - "near-rpc-error-core", + "base64 0.13.1", + "borsh 0.9.3", + "bs58 0.4.0", + "near-abi", + "near-sdk-macros 4.1.1", + "near-sys", + "once_cell", + "schemars", "serde", - "syn", + "serde_json", ] [[package]] name = "near-sdk" -version = "4.1.1" +version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" +checksum = "4e296b02c85539c16659e171242d6c6bbea87eec7c9ef860d8dfd3fb3168a18a" dependencies = [ - "base64 0.13.1", - "borsh", - "bs58", - "near-abi", - "near-crypto", - "near-primitives", - "near-primitives-core", - "near-sdk-macros", + "base64 0.22.1", + "borsh 1.5.1", + "bs58 0.5.1", + "near-account-id", + "near-gas", + "near-sdk-macros 5.5.0", "near-sys", - "near-vm-logic", + "near-token", "once_cell", - "schemars", "serde", "serde_json", "wee_alloc", @@ -929,47 +674,40 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] -name = "near-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e307313276eaeced2ca95740b5639e1f3125b7c97f0a1151809d105f1aa8c6d3" - -[[package]] -name = "near-vm-errors" -version = "0.14.0" +name = "near-sdk-macros" +version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" +checksum = "0adc79466aa556f56a995c0db34a933b32597ab92bbb0e526597118899c8bcaf" dependencies = [ - "borsh", - "near-account-id", - "near-rpc-error-macro", + "Inflector", + "darling", + "proc-macro2", + "quote", "serde", + "serde_json", + "strum", + "strum_macros", + "syn 2.0.79", ] [[package]] -name = "near-vm-logic" -version = "0.14.0" +name = "near-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf4ca5c805cb78700e10e43484902d8da05f25788db277999d209568aaf4c8e" + +[[package]] +name = "near-token" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2" +checksum = "cd3e60aa26a74dc514b1b6408fdd06cefe2eb0ff029020956c1c6517594048fd" dependencies = [ - "base64 0.13.1", - "borsh", - "bs58", - "byteorder", - "near-account-id", - "near-crypto", - "near-primitives", - "near-primitives-core", - "near-vm-errors", - "ripemd", + "borsh 1.5.1", "serde", - "sha2 0.10.6", - "sha3", - "zeropool-bn", ] [[package]] @@ -982,54 +720,11 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num-bigint" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" -dependencies = [ - "autocfg", - "num-bigint", - "num-integer", - "num-traits", - "serde", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - [[package]] name = "once_cell" -version = "1.17.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opaque-debug" @@ -1043,44 +738,6 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" -[[package]] -name = "parity-scale-codec" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909" -dependencies = [ - "arrayvec 0.7.2", - "bitvec", - "byte-slice-cast", - "impl-trait-for-tuples", - "parity-scale-codec-derive", - "serde", -] - -[[package]] -name = "parity-scale-codec-derive" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" -dependencies = [ - "proc-macro-crate 1.2.1", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "parity-secp256k1" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1" -dependencies = [ - "arrayvec 0.5.2", - "cc", - "cfg-if 0.1.10", - "rand 0.7.3", -] - [[package]] name = "peeking_take_while" version = "0.1.2" @@ -1094,41 +751,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] -name = "primitive-types" -version = "0.10.1" +name = "proc-macro-crate" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "fixed-hash", - "impl-codec", - "uint", + "toml", ] [[package]] name = "proc-macro-crate" -version = "0.1.5" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml", + "toml_edit", ] [[package]] -name = "proc-macro-crate" -version = "1.2.1" +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "once_cell", - "thiserror", - "toml", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", ] [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -1140,7 +807,7 @@ dependencies = [ "bindgen", "ed25519-dalek", "hex", - "near-sdk", + "near-sdk 5.5.0", "quickjs-rust-near-testenv", "sha2 0.10.6", ] @@ -1152,8 +819,8 @@ dependencies = [ "bindgen", "ed25519-dalek", "lazy_static", - "near-contract-standards", - "near-sdk", + "near-contract-standards 5.5.0", + "near-sdk 5.5.0", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -1163,7 +830,7 @@ name = "quickjs-rust-near-minimum-web4" version = "0.1.0" dependencies = [ "bindgen", - "near-sdk", + "near-sdk 5.5.0", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -1175,8 +842,8 @@ dependencies = [ "bindgen", "ed25519-dalek", "lazy_static", - "near-contract-standards", - "near-sdk", + "near-contract-standards 4.1.1", + "near-sdk 5.5.0", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -1186,7 +853,7 @@ name = "quickjs-rust-near-purejs" version = "0.1.0" dependencies = [ "bindgen", - "near-sdk", + "near-sdk 5.5.0", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -1197,25 +864,19 @@ version = "0.1.0" dependencies = [ "ed25519-dalek", "lazy_static", - "near-sdk", + "near-sdk 5.5.0", "sha2 0.10.6", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" - [[package]] name = "rand" version = "0.7.3" @@ -1224,22 +885,11 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom 0.1.16", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", "rand_hc", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -1247,17 +897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1269,31 +909,13 @@ dependencies = [ "getrandom 0.1.16", ] -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.8", -] - [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "reed-solomon-erasure" -version = "4.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a415a013dd7c5d4221382329a5a3482566da675737494935cbbbcdec04662f9d" -dependencies = [ - "smallvec", + "rand_core", ] [[package]] @@ -1313,36 +935,12 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest 0.10.6", -] - [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-hex" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rustversion" version = "1.0.11" @@ -1376,15 +974,9 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn", + "syn 1.0.107", ] -[[package]] -name = "scratch" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" - [[package]] name = "semver" version = "1.0.16" @@ -1408,7 +1000,7 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1419,7 +1011,7 @@ checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1457,16 +1049,6 @@ dependencies = [ "digest 0.10.6", ] -[[package]] -name = "sha3" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" -dependencies = [ - "digest 0.10.6", - "keccak", -] - [[package]] name = "shlex" version = "1.1.0" @@ -1479,35 +1061,6 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "smart-default" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" @@ -1516,24 +1069,21 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strum" -version = "0.24.1" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" -dependencies = [ - "strum_macros", -] +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" [[package]] name = "strum_macros" -version = "0.24.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck", "proc-macro2", "quote", "rustversion", - "syn", + "syn 2.0.79", ] [[package]] @@ -1553,6 +1103,29 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "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.79", +] + [[package]] name = "synstructure" version = "0.12.6" @@ -1561,16 +1134,10 @@ checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "unicode-xid", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "termcolor" version = "1.1.3" @@ -1587,35 +1154,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] -name = "thiserror" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.38" +name = "tinyvec" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ - "proc-macro2", - "quote", - "syn", + "tinyvec_macros", ] [[package]] -name = "time" -version = "0.1.45" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toml" @@ -1627,34 +1178,33 @@ dependencies = [ ] [[package]] -name = "typenum" -version = "1.16.0" +name = "toml_datetime" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] -name = "uint" -version = "0.9.5" +name = "toml_edit" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", + "indexmap 2.6.0", + "toml_datetime", + "winnow", ] [[package]] -name = "unicode-ident" -version = "1.0.6" +name = "typenum" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] -name = "unicode-width" -version = "0.1.10" +name = "unicode-ident" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-xid" @@ -1674,72 +1224,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" -dependencies = [ - "cfg-if 1.0.0", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" - [[package]] name = "wee_alloc" version = "0.4.5" @@ -1795,10 +1285,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "wyz" -version = "0.2.0" +name = "winnow" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] [[package]] name = "zeroize" @@ -1817,20 +1310,6 @@ checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "synstructure", ] - -[[package]] -name = "zeropool-bn" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71e61de68ede9ffdd69c01664f65a178c5188b73f78faa21f0936016a888ff7c" -dependencies = [ - "borsh", - "byteorder", - "crunchy", - "lazy_static", - "rand 0.8.5", - "rustc-hex", -] diff --git a/Cargo.toml b/Cargo.toml index ec60ba72..1331e3c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ strip="symbols" strip = false [dependencies] -near-sdk = "4.0.0" +near-sdk = "5.5.0" ed25519-dalek = "1.0.1" sha2 = "0.10.6" hex = "0.4.3" diff --git a/README.md b/README.md index b81f3003..8c1d9f91 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ The web application is packaged into a single HTML file using rollup, where the - **DONE** Running tests - **DONE** Displaying errors (needs a panic hook) - **DONE** Minimum NEAR mock env -- Local simulation in browser/node Wasm runtime with mocked NEAR env in JavaScript +- **DONE** Local simulation in browser/node Wasm runtime with mocked NEAR env in JavaScript - **DONE** End to End tests (testnet) - **DONE** Expose some NEAR environment functions to JS runtime - **DONE** `env.value_return` @@ -64,6 +64,4 @@ The web application is packaged into a single HTML file using rollup, where the - **DONE** `env.signer_account_id` (no need to load into register first) - **DONE** Web4 hosting showcase - **DONE** NFT implementation configurable with JavaScript -- Fungible Token example - - +- **DONE** Fungible Token example diff --git a/examples/fungibletoken/Cargo.toml b/examples/fungibletoken/Cargo.toml index bdd97eaa..e012bf0e 100644 --- a/examples/fungibletoken/Cargo.toml +++ b/examples/fungibletoken/Cargo.toml @@ -9,12 +9,12 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.0.0" +near-sdk = "5.5.0" lazy_static = "1.4.0" ed25519-dalek = "1.0.1" quickjs-rust-near = { path = "../../", features=["library"] } quickjs-rust-near-testenv = { path = "../../testenv" } -near-contract-standards = "4.1.1" +near-contract-standards = "5.5.0" [build-dependencies] bindgen = "0.60.1" diff --git a/examples/fungibletoken/src/lib.rs b/examples/fungibletoken/src/lib.rs index cbc2d6aa..68d81365 100644 --- a/examples/fungibletoken/src/lib.rs +++ b/examples/fungibletoken/src/lib.rs @@ -17,14 +17,16 @@ NOTES: */ use std::ffi::CString; +use near_contract_standards::storage_management::{StorageBalance, StorageBalanceBounds}; +use near_sdk::near; use near_contract_standards::fungible_token::metadata::{ FungibleTokenMetadata, FungibleTokenMetadataProvider, FT_METADATA_SPEC, }; use near_contract_standards::fungible_token::FungibleToken; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::collections::LazyOption; use near_sdk::json_types::U128; -use near_sdk::{env, log, near_bindgen, AccountId, Balance, PanicOnDefault, PromiseOrValue}; +use near_sdk::{env, log, near_bindgen, AccountId, NearToken, PanicOnDefault, PromiseOrValue}; use quickjs_rust_near::jslib::{ add_function_to_js, arg_to_str, compile_js, js_call_function, load_js_bytecode, to_js_string, }; @@ -33,6 +35,7 @@ const JS_BYTECODE_STORAGE_KEY: &[u8] = b"JS"; #[near_bindgen] #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] +#[borsh(crate="near_sdk::borsh")] pub struct Contract { token: FungibleToken, metadata: LazyOption, @@ -78,7 +81,7 @@ impl Contract { this.token.internal_deposit(&owner_id, total_supply.into()); near_contract_standards::fungible_token::events::FtMint { owner_id: &owner_id, - amount: &total_supply, + amount: total_supply, memo: Some("Initial tokens supply is minted"), } .emit(); @@ -134,8 +137,9 @@ impl Contract { add_function_to_js( "ft_balance_of", move |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { + let account_id = arg_to_str(ctx, 0, argv).parse().unwrap(); let balance = (*CONTRACT_REF) - .ft_balance_of(AccountId::new_unchecked(arg_to_str(ctx, 0, argv))) + .ft_balance_of(account_id) .0; return to_js_string(ctx, balance.to_string()); }, @@ -145,7 +149,7 @@ impl Contract { add_function_to_js( "ft_transfer", |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { - let receiver_id = AccountId::new_unchecked(arg_to_str(ctx, 0, argv)); + let receiver_id = arg_to_str(ctx, 0, argv).parse().unwrap(); let amount: U128 = U128(arg_to_str(ctx, 1, argv).parse::().unwrap()); (*CONTRACT_REF).ft_transfer(receiver_id, amount, None); return 0; @@ -172,17 +176,53 @@ impl Contract { self.store_js_bytecode(compile_js(javascript, Some("main.js".to_string()))); } - fn on_account_closed(&mut self, account_id: AccountId, balance: Balance) { + fn on_account_closed(&mut self, account_id: AccountId, balance: u128) { log!("Closed @{} with {}", account_id, balance); } - fn on_tokens_burned(&mut self, account_id: AccountId, amount: Balance) { + fn on_tokens_burned(&mut self, account_id: AccountId, amount: u128) { log!("Account @{} burned {}", account_id, amount); } } near_contract_standards::impl_fungible_token_core!(Contract, token, on_tokens_burned); -near_contract_standards::impl_fungible_token_storage!(Contract, token, on_account_closed); + + +#[near] +impl near_contract_standards::storage_management::StorageManagement for Contract { + #[payable] + fn storage_deposit( + &mut self, + account_id: Option, + registration_only: Option, + ) -> StorageBalance { + self.token.storage_deposit(account_id, registration_only) + } + + #[payable] + fn storage_withdraw(&mut self, amount: Option) -> StorageBalance { + self.token.storage_withdraw(amount) + } + + #[payable] + fn storage_unregister(&mut self, force: Option) -> bool { + #[allow(unused_variables)] + if let Some((account_id, balance)) = self.token.internal_storage_unregister(force) { + self.on_account_closed(account_id, balance); + true + } else { + false + } + } + + fn storage_balance_bounds(&self) -> StorageBalanceBounds { + self.token.storage_balance_bounds() + } + + fn storage_balance_of(&self, account_id: AccountId) -> Option { + self.token.storage_balance_of(account_id) + } +} #[near_bindgen] impl FungibleTokenMetadataProvider for Contract { @@ -193,16 +233,15 @@ impl FungibleTokenMetadataProvider for Contract { #[cfg(test)] mod tests { - use near_sdk::Balance; - use super::*; + use near_contract_standards::storage_management::StorageManagement; use quickjs_rust_near_testenv::testenv::{ alice, assert_latest_return_value_string_eq, bob, set_attached_deposit, set_block_timestamp, set_current_account_id, set_input, set_predecessor_account_id, setup_test_env, }; - const TOTAL_SUPPLY: Balance = 1_000_000_000_000_000; + const TOTAL_SUPPLY: u128 = 1_000_000_000_000_000; #[test] fn test_new() { @@ -225,7 +264,7 @@ mod tests { contract.storage_deposit(Some(alice()), Some(true)); set_predecessor_account_id(bob()); - set_attached_deposit(1); + set_attached_deposit(NearToken::from_yoctonear(1)); let transfer_amount = TOTAL_SUPPLY / 3; contract.ft_transfer(alice(), transfer_amount.into(), None); @@ -300,7 +339,7 @@ mod tests { contract.storage_deposit(Some(alice()), Some(true)); set_predecessor_account_id(bob()); - set_attached_deposit(1); + set_attached_deposit(NearToken::from_yoctonear(1)); contract.call_js_func("transfer_2_000_to_alice".to_string()); assert_eq!(contract.ft_balance_of(bob()).0, TOTAL_SUPPLY - 2_000); @@ -341,7 +380,7 @@ mod tests { contract.storage_deposit(Some(alice()), Some(true)); set_predecessor_account_id(bob()); - set_attached_deposit(1); + set_attached_deposit(NearToken::from_yoctonear(1)); set_block_timestamp(1234_000_000); contract.call_js_func("transfer_2_000_to_alice".to_string()); diff --git a/examples/minimumweb4/Cargo.toml b/examples/minimumweb4/Cargo.toml index 8b7a4eae..bfa7b20b 100644 --- a/examples/minimumweb4/Cargo.toml +++ b/examples/minimumweb4/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.1.1" +near-sdk = "5.5.0" quickjs-rust-near = { path = "../../", features=["library"] } quickjs-rust-near-testenv = { path = "../../testenv" } diff --git a/examples/nft/Cargo.toml b/examples/nft/Cargo.toml index e1a5ea7e..8570ba3c 100644 --- a/examples/nft/Cargo.toml +++ b/examples/nft/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.0.0" +near-sdk = "5.5.0" lazy_static = "1.4.0" ed25519-dalek = "1.0.1" quickjs-rust-near = { path = "../../", features=["library"] } diff --git a/examples/purejs/Cargo.toml b/examples/purejs/Cargo.toml index 786fde12..4bf42010 100644 --- a/examples/purejs/Cargo.toml +++ b/examples/purejs/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = "4.1.1" +near-sdk = "5.5.0" quickjs-rust-near = { path = "../../", features=["library"] } quickjs-rust-near-testenv = { path = "../../testenv" } diff --git a/src/lib.rs b/src/lib.rs index 3f35f42f..9bd83c7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ pub mod viewaccesscontrol; mod wasimock; #[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] +#[borsh(crate="near_sdk::borsh")] #[cfg(not(feature = "library"))] pub struct Scripts { scripts: HashMap>, diff --git a/src/viewaccesscontrol.rs b/src/viewaccesscontrol.rs index 0f7c2162..8ae2ba91 100644 --- a/src/viewaccesscontrol.rs +++ b/src/viewaccesscontrol.rs @@ -1,17 +1,19 @@ use ed25519_dalek::ed25519::signature::Signature as DalekSig; use ed25519_dalek::PublicKey as DalekPK; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::{base64, env}; use std::collections::HashMap; const ACCOUNT_SIGNING_KEYS_KEY: &[u8] = b"ACCSIGNKEYS"; #[derive(Default, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_sdk::borsh")] struct AccountSigningKey { public_key: Vec, expires_timestamp_ms: u64, } #[derive(Default, BorshDeserialize, BorshSerialize)] +#[borsh(crate = "near_sdk::borsh")] pub struct AccountSigningKeys { signing_keys_per_account: HashMap, } @@ -26,12 +28,11 @@ pub fn load_account_signing_keys() -> AccountSigningKeys { } pub fn save_account_signing_keys(account_signing_keys: AccountSigningKeys) { - env::storage_write( - ACCOUNT_SIGNING_KEYS_KEY, - &account_signing_keys - .try_to_vec() - .expect("Cannot serialize account signing keys."), - ); + let mut account_signing_keys_buffer: Vec = Vec::new(); + account_signing_keys + .serialize(&mut account_signing_keys_buffer) + .expect("Cannot serialize account signing keys."); + env::storage_write(ACCOUNT_SIGNING_KEYS_KEY, &account_signing_keys_buffer); } pub fn store_signing_key_for_account(expires_timestamp_ms: u64) { @@ -69,8 +70,9 @@ pub fn verify_message_signed_by_account( if account_signing_key_option.is_some() { let account_signing_key = account_signing_key_option.unwrap(); if account_signing_key.expires_timestamp_ms > env::block_timestamp_ms() { - let pk = DalekPK::from_bytes(&account_signing_key_option.unwrap().public_key[1..].to_vec()) - .unwrap(); + let pk = + DalekPK::from_bytes(&account_signing_key_option.unwrap().public_key[1..].to_vec()) + .unwrap(); let sig = DalekSig::from_bytes(base64::decode(&signature).unwrap().as_slice()).unwrap(); return pk.verify_strict(signed_message.as_bytes(), &sig).is_ok(); @@ -84,11 +86,11 @@ mod tests { use super::{ load_account_signing_keys, store_signing_key_for_account, verify_message_signed_by_account, }; + use near_sdk::env::block_timestamp_ms; use quickjs_rust_near_testenv::testenv::{ alice, bob, set_block_timestamp, set_signer_account_id, set_signer_account_pk, setup_test_env, }; - use near_sdk::env::{block_timestamp_ms}; const EXPIRY_MILLISECONDS: u64 = 24 * 60 * 60 * 1000; #[test] diff --git a/testenv/Cargo.toml b/testenv/Cargo.toml index dfc09f4f..4b83d40f 100644 --- a/testenv/Cargo.toml +++ b/testenv/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -near-sdk = "4.0.0" +near-sdk = "5.5.0" lazy_static = "1.4.0" ed25519-dalek = "1.0.1" sha2 = "0.10.6" diff --git a/testenv/src/testenv.rs b/testenv/src/testenv.rs index 94203ccd..31f936b3 100644 --- a/testenv/src/testenv.rs +++ b/testenv/src/testenv.rs @@ -1,4 +1,4 @@ -use near_sdk::{AccountId, Balance, PublicKey}; +use near_sdk::{AccountId, NearToken, PublicKey}; use sha2::Digest; use std::collections::HashMap; use std::io::{self, Write}; @@ -7,17 +7,17 @@ const EVICTED_REGISTER: i64 = (u64::MAX - 1) as i64; #[allow(dead_code)] pub fn alice() -> AccountId { - AccountId::new_unchecked("alice.near".to_string()) + "alice.near".parse().unwrap() } #[allow(dead_code)] pub fn bob() -> AccountId { - AccountId::new_unchecked("bob.near".to_string()) + "bob.near".parse().unwrap() } #[allow(dead_code)] pub fn carol() -> AccountId { - AccountId::new_unchecked("carol.near".to_string()) + "carol.near".parse().unwrap() } struct TestEnv { @@ -26,7 +26,7 @@ struct TestEnv { signer_account_pk: PublicKey, current_account_id: AccountId, predecessor_account_id: AccountId, - attached_deposit: Balance, + attached_deposit: NearToken, input: Vec, returned_value: Vec, } @@ -38,7 +38,7 @@ impl TestEnv { signer_account_id: bob(), current_account_id: alice(), predecessor_account_id: bob(), - attached_deposit: 0, + attached_deposit: NearToken::from_near(0), signer_account_pk: vec![ 00, 66, 211, 21, 84, 20, 241, 129, 29, 118, 83, 184, 41, 215, 240, 117, 106, 56, 29, 69, 103, 43, 191, 167, 199, 102, 3, 16, 194, 250, 138, 198, 78, @@ -113,7 +113,7 @@ pub fn set_input(input: Vec) { } } -pub fn set_attached_deposit(deposit: Balance) { +pub fn set_attached_deposit(deposit: NearToken) { unsafe { if let Some(test_env) = TESTENV.as_mut() { test_env.attached_deposit = deposit; @@ -205,7 +205,7 @@ pub extern "C" fn input(register: i64) { pub extern "C" fn attached_deposit(data_ptr: i64) { unsafe { let testenv = TESTENV.as_ref().unwrap(); - let src = testenv.attached_deposit.to_le_bytes(); + let src = testenv.attached_deposit.as_yoctonear().to_le_bytes(); std::ptr::copy(src.as_ptr(), data_ptr as *mut u8, src.len()); } } From c790fa3ee17988c82d9de901221532676b18a97f Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Fri, 11 Oct 2024 13:03:09 +0200 Subject: [PATCH 2/8] nft contract sdk 5.5.0 --- Cargo.lock | 255 ++++------------------------------------ examples/nft/Cargo.toml | 2 +- examples/nft/src/lib.rs | 29 +++-- 3 files changed, 38 insertions(+), 248 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b6482f9..d2af0fba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,17 +8,6 @@ version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom 0.2.8", - "once_cell", - "version_check", -] - [[package]] name = "aho-corasick" version = "0.7.20" @@ -45,12 +34,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.22.1" @@ -104,39 +87,16 @@ dependencies = [ "generic-array", ] -[[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 = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" dependencies = [ - "borsh-derive 1.5.1", + "borsh-derive", "cfg_aliases", ] -[[package]] -name = "borsh-derive" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" -dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", - "proc-macro-crate 0.1.5", - "proc-macro2", - "syn 1.0.107", -] - [[package]] name = "borsh-derive" version = "1.5.1" @@ -144,41 +104,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" dependencies = [ "once_cell", - "proc-macro-crate 3.2.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.79", "syn_derive", ] -[[package]] -name = "borsh-derive-internal" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.107", -] - -[[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.107", -] - -[[package]] -name = "bs58" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" - [[package]] name = "bs58" version = "0.5.1" @@ -341,12 +273,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dyn-clone" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9b0705efd4599c15a38151f4721f7bc388306f61084d3bfd50bd07fbca5cb60" - [[package]] name = "ed25519" version = "1.5.2" @@ -419,18 +345,7 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -439,15 +354,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -574,47 +480,23 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "near-abi" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73" -dependencies = [ - "borsh 0.9.3", - "schemars", - "semver", - "serde", -] - [[package]] name = "near-account-id" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35cbb989542587b47205e608324ddd391f0cee1c22b4b64ae49f458334b95907" dependencies = [ - "borsh 1.5.1", + "borsh", "serde", ] -[[package]] -name = "near-contract-standards" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bacc932e79b26472797adfb21689294b6f90960d1570daaf1e0b682b59fcb35" -dependencies = [ - "near-sdk 4.1.1", - "schemars", - "serde", - "serde_json", -] - [[package]] name = "near-contract-standards" version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3b985c4df43237b6ae533a6451cfa13de1f12f79f7d6254ba376f0ccd017286" dependencies = [ - "near-sdk 5.5.0", + "near-sdk", ] [[package]] @@ -623,26 +505,8 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180edcc7dc2fac41f93570d0c7b759c1b6d492f6ad093d749d644a40b4310a97" dependencies = [ - "borsh 1.5.1", - "serde", -] - -[[package]] -name = "near-sdk" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" -dependencies = [ - "base64 0.13.1", - "borsh 0.9.3", - "bs58 0.4.0", - "near-abi", - "near-sdk-macros 4.1.1", - "near-sys", - "once_cell", - "schemars", + "borsh", "serde", - "serde_json", ] [[package]] @@ -651,12 +515,12 @@ version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e296b02c85539c16659e171242d6c6bbea87eec7c9ef860d8dfd3fb3168a18a" dependencies = [ - "base64 0.22.1", - "borsh 1.5.1", - "bs58 0.5.1", + "base64", + "borsh", + "bs58", "near-account-id", "near-gas", - "near-sdk-macros 5.5.0", + "near-sdk-macros", "near-sys", "near-token", "once_cell", @@ -665,18 +529,6 @@ dependencies = [ "wee_alloc", ] -[[package]] -name = "near-sdk-macros" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4907affc9f5ed559456509188ff0024f1f2099c0830e6bdb66eb61d5b75912c0" -dependencies = [ - "Inflector", - "proc-macro2", - "quote", - "syn 1.0.107", -] - [[package]] name = "near-sdk-macros" version = "5.5.0" @@ -706,7 +558,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd3e60aa26a74dc514b1b6408fdd06cefe2eb0ff029020956c1c6517594048fd" dependencies = [ - "borsh 1.5.1", + "borsh", "serde", ] @@ -750,15 +602,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -807,7 +650,7 @@ dependencies = [ "bindgen", "ed25519-dalek", "hex", - "near-sdk 5.5.0", + "near-sdk", "quickjs-rust-near-testenv", "sha2 0.10.6", ] @@ -819,8 +662,8 @@ dependencies = [ "bindgen", "ed25519-dalek", "lazy_static", - "near-contract-standards 5.5.0", - "near-sdk 5.5.0", + "near-contract-standards", + "near-sdk", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -830,7 +673,7 @@ name = "quickjs-rust-near-minimum-web4" version = "0.1.0" dependencies = [ "bindgen", - "near-sdk 5.5.0", + "near-sdk", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -842,8 +685,8 @@ dependencies = [ "bindgen", "ed25519-dalek", "lazy_static", - "near-contract-standards 4.1.1", - "near-sdk 5.5.0", + "near-contract-standards", + "near-sdk", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -853,7 +696,7 @@ name = "quickjs-rust-near-purejs" version = "0.1.0" dependencies = [ "bindgen", - "near-sdk 5.5.0", + "near-sdk", "quickjs-rust-near", "quickjs-rust-near-testenv", ] @@ -864,7 +707,7 @@ version = "0.1.0" dependencies = [ "ed25519-dalek", "lazy_static", - "near-sdk 5.5.0", + "near-sdk", "sha2 0.10.6", ] @@ -883,7 +726,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.16", + "getrandom", "libc", "rand_chacha", "rand_core", @@ -906,7 +749,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.16", + "getrandom", ] [[package]] @@ -953,36 +796,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" -[[package]] -name = "schemars" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 1.0.107", -] - -[[package]] -name = "semver" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" - [[package]] name = "serde" version = "1.0.152" @@ -1003,17 +816,6 @@ dependencies = [ "syn 1.0.107", ] -[[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.107", -] - [[package]] name = "serde_json" version = "1.0.91" @@ -1168,15 +970,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "toml" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" -dependencies = [ - "serde", -] - [[package]] name = "toml_datetime" version = "0.6.8" @@ -1224,12 +1017,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wee_alloc" version = "0.4.5" diff --git a/examples/nft/Cargo.toml b/examples/nft/Cargo.toml index 8570ba3c..a77e344b 100644 --- a/examples/nft/Cargo.toml +++ b/examples/nft/Cargo.toml @@ -14,7 +14,7 @@ lazy_static = "1.4.0" ed25519-dalek = "1.0.1" quickjs-rust-near = { path = "../../", features=["library"] } quickjs-rust-near-testenv = { path = "../../testenv" } -near-contract-standards = "4.1.1" +near-contract-standards = "5.5.0" [build-dependencies] bindgen = "0.60.1" diff --git a/examples/nft/src/lib.rs b/examples/nft/src/lib.rs index b4de7f67..77c17e6e 100644 --- a/examples/nft/src/lib.rs +++ b/examples/nft/src/lib.rs @@ -5,9 +5,9 @@ use near_contract_standards::non_fungible_token::metadata::{ }; use near_contract_standards::non_fungible_token::{NonFungibleToken, Token, TokenId}; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::json_types::U128; -use near_sdk::{ +use near_sdk::{near, assert_one_yocto, base64, env, near_bindgen, serde_json, AccountId, BorshStorageKey, PanicOnDefault, Promise, PromiseOrValue, }; @@ -23,6 +23,7 @@ const JS_BYTECODE_STORAGE_KEY: &[u8] = b"JS"; const JS_CONTENT_RESOURCE_PREFIX: &str = "JSC_"; #[derive(BorshSerialize, BorshStorageKey)] +#[borsh(crate="near_sdk::borsh")] enum StorageKey { NonFungibleToken, TokenMetadata, @@ -32,6 +33,7 @@ enum StorageKey { #[near_bindgen] #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] +#[borsh(crate="near_sdk::borsh")] pub struct Contract { tokens: NonFungibleToken, } @@ -75,7 +77,7 @@ impl Contract { "nft_supply_for_owner", |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { return (*CONTRACT_REF) - .nft_supply_for_owner(AccountId::new_unchecked(arg_to_str(ctx, 0, argv))) + .nft_supply_for_owner(arg_to_str(ctx, 0, argv).parse().unwrap()) .0 as i64; }, 1, @@ -310,6 +312,7 @@ mod tests { use super::*; + use near_sdk::NearToken; use quickjs_rust_near::jslib::compile_js; use quickjs_rust_near_testenv::testenv::{ alice, assert_latest_return_value_contains, assert_latest_return_value_string_eq, bob, @@ -344,7 +347,7 @@ mod tests { setup_test_env(); set_current_account_id(bob()); set_predecessor_account_id(bob()); - set_attached_deposit(1640000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(1640000000000000000000)); let mut contract = Contract::new(); contract.post_javascript( @@ -367,7 +370,7 @@ mod tests { contract.call_js_func("get_supply_for_bob".to_string()); assert_latest_return_value_string_eq("bob supply: 0".to_string()); - set_attached_deposit(1900000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(1900000000000000000000)); contract.nft_mint("abc".to_string(), bob()); assert_eq!(contract.nft_supply_for_owner(bob()).0, 1 as u128); @@ -404,7 +407,7 @@ mod tests { ); set_signer_account_id(alice()); - set_attached_deposit(10440000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(10440000000000000000000)); contract.nft_mint("2222".to_string(), alice()); @@ -471,7 +474,7 @@ mod tests { assert_eq!( contract - .nft_supply_for_owner(AccountId::new_unchecked("unknown.near".to_string())) + .nft_supply_for_owner("unknown.near".parse().unwrap()) .0, 0 as u128 ); @@ -512,7 +515,7 @@ mod tests { setup_test_env(); set_current_account_id(carol()); set_predecessor_account_id(carol()); - set_attached_deposit(1900000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(1900000000000000000000)); let mut contract = Contract::new(); contract.post_javascript( @@ -571,7 +574,7 @@ mod tests { .to_string(), ); - set_attached_deposit(1960000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(1960000000000000000000)); let token_id = "554433".to_string(); contract.nft_mint(token_id.to_owned(), bob()); @@ -619,7 +622,7 @@ mod tests { .to_string(), ); - set_attached_deposit(2000000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(2000000000000000000000)); let token_id = "5544332".to_string(); contract.nft_mint(token_id.to_owned(), alice()); @@ -706,7 +709,7 @@ mod tests { " .to_string(), ); - set_attached_deposit(1860000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(1860000000000000000000)); contract.nft_mint("1".to_string(), bob()); contract.call_js_func("get_nft_token".to_string()); @@ -737,7 +740,7 @@ mod tests { .to_string(), ); - set_attached_deposit(2080000000000000000000); + set_attached_deposit(NearToken::from_yoctonear(2080000000000000000000)); let token_id = "burn_me_now".to_string(); contract.nft_mint(token_id.to_owned(), burn_account.to_owned()); @@ -756,7 +759,7 @@ mod tests { "burn_me_now" ); - set_attached_deposit(1); + set_attached_deposit(NearToken::from_yoctonear(1)); contract.nft_burn(token_id); assert_eq!(contract.nft_token("burn_me_now".to_string()), None); From d9841dcf496a405bde3a7fdccafa74e555189208 Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Fri, 11 Oct 2024 13:04:14 +0200 Subject: [PATCH 3/8] minimum web4 ready for sdk 5.5 --- examples/minimumweb4/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/minimumweb4/src/lib.rs b/examples/minimumweb4/src/lib.rs index 8462bce8..d25efe51 100644 --- a/examples/minimumweb4/src/lib.rs +++ b/examples/minimumweb4/src/lib.rs @@ -10,6 +10,7 @@ const JS_CONTENT_RESOURCE_PREFIX: &str = "JSC_"; #[near_bindgen] #[derive(BorshDeserialize, BorshSerialize, Default)] +#[borsh(crate="near_sdk::borsh")] pub struct Contract {} static mut CONTRACT_REF: *const Contract = 0 as *const Contract; From f875aa5b5290a41c79ad5ccd2ab83d9e2c6a3f5d Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Fri, 11 Oct 2024 13:10:33 +0200 Subject: [PATCH 4/8] purejs example for near-sdk 5.5 --- examples/purejs/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/purejs/src/lib.rs b/examples/purejs/src/lib.rs index 0192e729..40297a6f 100644 --- a/examples/purejs/src/lib.rs +++ b/examples/purejs/src/lib.rs @@ -1,18 +1,17 @@ -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::near_bindgen; -use quickjs_rust_near::jslib::{ - js_call_function, load_js_bytecode -}; +use quickjs_rust_near::jslib::{js_call_function, load_js_bytecode}; #[near_bindgen] #[derive(BorshDeserialize, BorshSerialize, Default)] +#[borsh(crate = "near_sdk::borsh")] pub struct Contract {} #[near_bindgen] impl Contract { pub fn some_js_function(&self) { - unsafe { - let jsmod = load_js_bytecode(123456789 as *const u8, 987654321); + unsafe { + let jsmod = load_js_bytecode(123456789 as *const u8, 987654321); js_call_function(jsmod, 456123987 as i32); } } From ec4da57cdc8ab1d9ac3a265205f8adb667ad6108 Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Sun, 13 Oct 2024 03:32:41 +0200 Subject: [PATCH 5/8] updated readme files --- README.md | 69 +++++++++------------------------- examples/minimumweb4/README.md | 23 ++++++++++++ web4/README.md | 7 ++++ 3 files changed, 48 insertions(+), 51 deletions(-) create mode 100644 examples/minimumweb4/README.md create mode 100644 web4/README.md diff --git a/README.md b/README.md index 8c1d9f91..c4f46a98 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,34 @@ -Rust WebAssembly smart contract for NEAR with Javascript runtime +Rust WebAssembly smart contracts for NEAR with Javascript runtime ================================================================ -This is a Proof of Concept of embedding QuickJS with https://github.com/near/near-sdk-rs for being able to execute custom JavaScript code inside a smart contract written in Rust. +This project shows compiling and embedding [QuickJS](https://bellard.org/quickjs/) with https://github.com/near/near-sdk-rs for being able to execute custom JavaScript code inside a smart contract written in Rust. It contains examples of standard contracts like NFT and Fungible token, with JavaScript customization layers on top. There are also examples of a [web4](https://github.com/vgrichina/web4) contract. -First of all, have a look at the videos where I present the project +Check out the youtube playlist with videos showing the project: https://www.youtube.com/watch?v=JBZEr__pid0&list=PLv5wm4YuO4IwVNrSsYxeqKrtQZYRML03Z -The QuickJS runtime is compiled from https://github.com/petersalomonsen/quickjs-wasm-near +Also check out the [end-to-end](#end-to-end-tests-using-near-workspaces) tests for how to use the contracts from this project. -The contract has two functions: -- `run_script` accepting javascript as text for compiling on the fly. -- `run_bytecode` for running JS pre-compiled into the QuickJS bytecode format. Send the pre-compiled bytecode as a base64 string. See https://github.com/petersalomonsen/quickjs-wasm-near/blob/master/web/compiler/compile.spec.js for examples on compiling JS to QuickJS bytecode. -- `submit_script` for submitting and storing JavaScript and running later -- `run_script_for_account` run script stored by account, returns an integer returned by the script -- `run_script_for_account_no_return` run script stored by account, does not return anything unless the script calls `env.value_return`. +# Architecture / structure -For building and deploying the contract have a look at [buildanddeploy.sh](./buildanddeploy.sh). +QuickJS is built with [Emscripten](https://emscripten.org/) to a static library. Another C library, which can be found in the [quickjslib](./quickjslib/) folder, is providing a simplified interface to QuickJS, which is then linked to the Rust code along with other relevant static libraries from the Emscripten distribution ( such as the C standard library, allocator, WASI etc. ). -# Calling the deployed contract +See the entire build process in [build.rs](./build.rs). -Test running javascript as text: +In the Rust part, there are contract implementations exposing functions for submitting JavaScript code. Both in the internal bytecode format of QuickJS, and pure JS source code. -``` -near call dev-1650299983789-21350249865305 --accountId=psalomo.testnet run_script '{"script": "(function() {return 5*33+22;})();" }' -``` +# Unit tests running in WebAssembly -Here are some examples from a deployment to testnet account: `dev-1650299983789-21350249865305` +While it's common and more straightforward for NEAR smart contracts and many other Rust WebAssembly projects, to have their unit tests compiled to the native platform, this project runs the unit test in a WebAssembly runtime. The reason for this is because of the static libraries compiled from C, which are already targeting Wasm. One limitation when running tests inside the Wasm runtime is that you cannot catch panics, and so testing the error messages has to be done in the end-2-end tests -Test running bytecode ( which is compiled from `JSON.parse('{"a": 222}').a+3`): +# End-to-end tests using near-workspaces -``` -near call dev-1650299983789-21350249865305 --accountId=psalomo.testnet run_bytecode '{"bytecodebase64": "AgQKcGFyc2UUeyJhIjogMjIyfQJhGDxldmFsc291cmNlPg4ABgCgAQABAAMAABsBogEAAAA4mwAAAELeAAAABN8AAAAkAQBB4AAAALidzSjCAwEA" }' -``` -# Testing +In the [e2e](./e2e/) folder and also within the [examples](./examples/) folders there are test files that demonstrates deployment and interaction with the contract using [near-workspaces-js](https://github.com/near/near-workspaces-js). All these tests are being run as part of the github actions pipeline, but you can also look at this for examples on how to use the contracts produced in this project. -Since we are linking with C libraries it is more practical to have Wasm pre-builds and run tests in a Wasm target rather than having builds for native platforms. Run the test using wasi like this: +# Example contracts -`RUSTFLAGS='-C link-args=--initial-memory=67108864' cargo wasi test -- --show-output --nocapture` - -Unfortunately testing with wasi has some limitations today. Especially panic does not support unwinding in Wasm, and so tests that should panic needs to be performed in e2e test scenarios. Read more here: https://bytecodealliance.github.io/cargo-wasi/testing.html - -# Web4 and a WebAssembly Music showcase - -The web application in the [web4](./web4) folder is a vanilla JS Web Component application for uploading music written in Javascript and also playing it, and accepting parameters in JSON for configuring the playback. It also contains functionality for exporting to WAV. See the video playlist above for a demo. - -The music to be played back is fetched in a view method call, and for controlling who can access this view method the JSON parameters payload is signed using the callers private key. The contract will then verify the signature according to the callers public key stored in a transaction before the view method call. - -The web application is packaged into a single HTML file using rollup, where the final bundle is embedded into the Rust sources encoded as a base64 string. - -# TODO - -- **DONE** Implement (mock) WASI methods in a linkable library so that WAT file does not have to be edited manually -- **DONE** Integration/Unit testing support for Wasm32 target ( which is not supported with near-sdk-rs, see https://github.com/near/near-sdk-rs/issues/467 ) - - **DONE** Running tests - - **DONE** Displaying errors (needs a panic hook) - - **DONE** Minimum NEAR mock env -- **DONE** Local simulation in browser/node Wasm runtime with mocked NEAR env in JavaScript -- **DONE** End to End tests (testnet) -- **DONE** Expose some NEAR environment functions to JS runtime - - **DONE** `env.value_return` - - **DONE** `env.input` (no need to load into register first) - - **DONE** `env.signer_account_id` (no need to load into register first) -- **DONE** Web4 hosting showcase -- **DONE** NFT implementation configurable with JavaScript -- **DONE** Fungible Token example +- [NFT](./examples/nft/README.md) +- [Fungible Token](./examples/fungibletoken/README.md) +- [Minimum Web4](./examples/minimumweb4/README.md) +- "[PureJS](./examples/purejs/README.md) +- [Web4 and a WebAssembly Music showcase](./web4/README.md) diff --git a/examples/minimumweb4/README.md b/examples/minimumweb4/README.md new file mode 100644 index 00000000..9e608352 --- /dev/null +++ b/examples/minimumweb4/README.md @@ -0,0 +1,23 @@ +Web4 +==== + +This contract allows you to create a [web4](https://github.com/vgrichina/web4) contract where you can implement the Web4 interfaces in Javascript. + +Example: + +```javascript +export function web4_get() { + const request = JSON.parse(env.input()).request; + + let response; + + if (request.path == '/index.html') { + response = { + contentType: "text/html; charset=UTF-8", + body: env.base64_encode("Hello") + }; + } + env.value_return(JSON.stringify(response)); +} +``` + diff --git a/web4/README.md b/web4/README.md new file mode 100644 index 00000000..0382da0c --- /dev/null +++ b/web4/README.md @@ -0,0 +1,7 @@ +# Web4 and a WebAssembly Music showcase + +The web application in the [web4](./web4) folder is a vanilla JS Web Component application for uploading music written in Javascript and also playing it, and accepting parameters in JSON for configuring the playback. It also contains functionality for exporting to WAV. See the video playlist above for a demo. + +The music to be played back is fetched in a view method call, and for controlling who can access this view method the JSON parameters payload is signed using the callers private key. The contract will then verify the signature according to the callers public key stored in a transaction before the view method call. + +The web application is packaged into a single HTML file using rollup, where the final bundle is embedded into the Rust sources encoded as a base64 string. From e736d58888546658b621f117e9f00856406a30be Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Sun, 13 Oct 2024 10:12:38 +0200 Subject: [PATCH 6/8] local js test environment docs --- README.md | 20 +++++++++++++++----- localjstestenv/README.md | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 localjstestenv/README.md diff --git a/README.md b/README.md index c4f46a98..02a1c632 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ https://www.youtube.com/watch?v=JBZEr__pid0&list=PLv5wm4YuO4IwVNrSsYxeqKrtQZYRML Also check out the [end-to-end](#end-to-end-tests-using-near-workspaces) tests for how to use the contracts from this project. +# Devcontainer / github actions + +All the pre-requisities for getting the project up and running can be found in the [.devcontainer](./.devcontainer) folder, which will be automaticall set up if using a github codespace. + +The github actions also shows how to build and run all the examples. + # Architecture / structure QuickJS is built with [Emscripten](https://emscripten.org/) to a static library. Another C library, which can be found in the [quickjslib](./quickjslib/) folder, is providing a simplified interface to QuickJS, which is then linked to the Rust code along with other relevant static libraries from the Emscripten distribution ( such as the C standard library, allocator, WASI etc. ). @@ -25,10 +31,14 @@ While it's common and more straightforward for NEAR smart contracts and many oth In the [e2e](./e2e/) folder and also within the [examples](./examples/) folders there are test files that demonstrates deployment and interaction with the contract using [near-workspaces-js](https://github.com/near/near-workspaces-js). All these tests are being run as part of the github actions pipeline, but you can also look at this for examples on how to use the contracts produced in this project. +# Local JS test environment + +A simple mocking of NEAR interfaces for simulation of a smart contract directly in NodeJS or in the browser can be found in [localjstestenv](./localjstestenv/README.md). + # Example contracts -- [NFT](./examples/nft/README.md) -- [Fungible Token](./examples/fungibletoken/README.md) -- [Minimum Web4](./examples/minimumweb4/README.md) -- "[PureJS](./examples/purejs/README.md) -- [Web4 and a WebAssembly Music showcase](./web4/README.md) +- [NFT](./examples/nft/README.md) - The standard NFT contract, customizable with JavaScript +- [Fungible Token](./examples/fungibletoken/README.md) - The standard FT contract, customizable with JavaScript +- [Minimum Web4](./examples/minimumweb4/README.md) - Implement the web4 interface in JavaScript to serve a website from the smart contract +- "[PureJS](./examples/purejs/README.md)" - Precompile the JS bytecode into the contract, and provide direct exports to the JS functions. +- [Web4 and a WebAssembly Music showcase](./web4/README.md) - JavaScript from WebAssembly Music running in the smart contract diff --git a/localjstestenv/README.md b/localjstestenv/README.md new file mode 100644 index 00000000..1a9b0588 --- /dev/null +++ b/localjstestenv/README.md @@ -0,0 +1,15 @@ +A minimal environment for simulation of WASM smart contracts +============================================================ + +Sometimes spinning up near-workspaces might not be needed if you're only going to simulate view methods or storage. By mocking the NEAR environment imports you can easily and fast spin up a smart contract runner for such simple use cases. + +Given you have a simple contract `my-contract.wasm` that exports a view function named `hello`, and you can provide `name` as an argument, you can test that it returns a given value like shown in the example below. + +```javascript +import { getContractInstanceExports } from "./contract-runner.js"; + +const { exports, nearenv } = await getContractInstanceExports(await readFile('./my-contract.wasm')); +nearenv.set_args({ name: 'peter' }); +exports.hello(); +expect(nearenv.latest_return_value).to.equal('hello peter'); +``` From 6d1123d95857a7c16da3b9a1f952e8e23ee0a97c Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Mon, 14 Oct 2024 19:16:08 +0200 Subject: [PATCH 7/8] add ft_transfer_internal to FT contract and test without attaching 1 yocto near --- examples/fungibletoken/src/lib.rs | 57 +++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/examples/fungibletoken/src/lib.rs b/examples/fungibletoken/src/lib.rs index 68d81365..3b642644 100644 --- a/examples/fungibletoken/src/lib.rs +++ b/examples/fungibletoken/src/lib.rs @@ -17,15 +17,15 @@ NOTES: */ use std::ffi::CString; -use near_contract_standards::storage_management::{StorageBalance, StorageBalanceBounds}; -use near_sdk::near; use near_contract_standards::fungible_token::metadata::{ FungibleTokenMetadata, FungibleTokenMetadataProvider, FT_METADATA_SPEC, }; use near_contract_standards::fungible_token::FungibleToken; +use near_contract_standards::storage_management::{StorageBalance, StorageBalanceBounds}; use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::collections::LazyOption; use near_sdk::json_types::U128; +use near_sdk::near; use near_sdk::{env, log, near_bindgen, AccountId, NearToken, PanicOnDefault, PromiseOrValue}; use quickjs_rust_near::jslib::{ add_function_to_js, arg_to_str, compile_js, js_call_function, load_js_bytecode, to_js_string, @@ -35,7 +35,7 @@ const JS_BYTECODE_STORAGE_KEY: &[u8] = b"JS"; #[near_bindgen] #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] -#[borsh(crate="near_sdk::borsh")] +#[borsh(crate = "near_sdk::borsh")] pub struct Contract { token: FungibleToken, metadata: LazyOption, @@ -138,9 +138,7 @@ impl Contract { "ft_balance_of", move |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { let account_id = arg_to_str(ctx, 0, argv).parse().unwrap(); - let balance = (*CONTRACT_REF) - .ft_balance_of(account_id) - .0; + let balance = (*CONTRACT_REF).ft_balance_of(account_id).0; return to_js_string(ctx, balance.to_string()); }, 1, @@ -156,6 +154,20 @@ impl Contract { }, 2, ); + + add_function_to_js( + "ft_transfer_internal", + |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { + let sender_id = env::predecessor_account_id(); + let receiver_id = arg_to_str(ctx, 0, argv).parse().unwrap(); + let amount: U128 = U128(arg_to_str(ctx, 1, argv).parse::().unwrap()); + (*CONTRACT_REF) + .token + .internal_transfer(&sender_id, &receiver_id, amount.0, None); + return 0; + }, + 2, + ); } #[payable] @@ -187,7 +199,6 @@ impl Contract { near_contract_standards::impl_fungible_token_core!(Contract, token, on_tokens_burned); - #[near] impl near_contract_standards::storage_management::StorageManagement for Contract { #[payable] @@ -398,4 +409,36 @@ mod tests { assert_eq!(contract.ft_balance_of(bob()).0, TOTAL_SUPPLY - 1_000); assert_eq!(contract.ft_balance_of(alice()).0, 1_000); } + + #[test] + fn test_js_transfer_without_attached_neartokens() { + setup_test_env(); + + let mut contract = Contract::new_default_meta(bob().into(), TOTAL_SUPPLY.into()); + set_current_account_id(bob()); + set_predecessor_account_id(bob()); + contract.post_javascript( + " + export function transfer_2_000_to_alice() { + const amount = 2_000n; + env.ft_transfer_internal('alice.near', amount.toString()); + env.value_return(transfer_id); + }" + .to_string(), + ); + + set_predecessor_account_id(alice()); + set_attached_deposit(contract.storage_balance_bounds().min.into()); + + // Paying for account registration, aka storage deposit + contract.storage_deposit(Some(alice()), Some(true)); + + set_predecessor_account_id(bob()); + //set_attached_deposit(NearToken::from_yoctonear(1)); + + set_block_timestamp(1234_000_000); + contract.call_js_func("transfer_2_000_to_alice".to_string()); + assert_eq!(contract.ft_balance_of(bob()).0, TOTAL_SUPPLY - 2_000); + assert_eq!(contract.ft_balance_of(alice()).0, 2_000); + } } From 523607471221aacca3a56c1f9fb5322781c59d5a Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Tue, 15 Oct 2024 06:50:07 +0200 Subject: [PATCH 8/8] also add the option to specify sender id for ft_transfer_internal --- examples/fungibletoken/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/fungibletoken/src/lib.rs b/examples/fungibletoken/src/lib.rs index 3b642644..ee1abde9 100644 --- a/examples/fungibletoken/src/lib.rs +++ b/examples/fungibletoken/src/lib.rs @@ -158,9 +158,9 @@ impl Contract { add_function_to_js( "ft_transfer_internal", |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { - let sender_id = env::predecessor_account_id(); - let receiver_id = arg_to_str(ctx, 0, argv).parse().unwrap(); - let amount: U128 = U128(arg_to_str(ctx, 1, argv).parse::().unwrap()); + let sender_id = arg_to_str(ctx, 0, argv).parse().unwrap(); + let receiver_id = arg_to_str(ctx, 1, argv).parse().unwrap(); + let amount: U128 = U128(arg_to_str(ctx, 2, argv).parse::().unwrap()); (*CONTRACT_REF) .token .internal_transfer(&sender_id, &receiver_id, amount.0, None); @@ -411,7 +411,7 @@ mod tests { } #[test] - fn test_js_transfer_without_attached_neartokens() { + fn test_js_transfer_internal_without_attached_neartokens() { setup_test_env(); let mut contract = Contract::new_default_meta(bob().into(), TOTAL_SUPPLY.into()); @@ -419,9 +419,9 @@ mod tests { set_predecessor_account_id(bob()); contract.post_javascript( " - export function transfer_2_000_to_alice() { + export function transfer_2_000_from_bob_to_alice() { const amount = 2_000n; - env.ft_transfer_internal('alice.near', amount.toString()); + env.ft_transfer_internal('bob.near','alice.near', amount.toString()); env.value_return(transfer_id); }" .to_string(), @@ -434,10 +434,10 @@ mod tests { contract.storage_deposit(Some(alice()), Some(true)); set_predecessor_account_id(bob()); - //set_attached_deposit(NearToken::from_yoctonear(1)); + set_attached_deposit(NearToken::from_yoctonear(0)); set_block_timestamp(1234_000_000); - contract.call_js_func("transfer_2_000_to_alice".to_string()); + contract.call_js_func("transfer_2_000_from_bob_to_alice".to_string()); assert_eq!(contract.ft_balance_of(bob()).0, TOTAL_SUPPLY - 2_000); assert_eq!(contract.ft_balance_of(alice()).0, 2_000); }