From 4a4302402103573545b00ec4538ff2d72af6bd47 Mon Sep 17 00:00:00 2001 From: datben Date: Wed, 15 Mar 2023 21:21:06 +0100 Subject: [PATCH 1/4] upd gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index df2ad90..6088d06 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ target/ # MSVC Windows builds of rustc generate these, which store debugging information *.pdb +**/.DS_STORE + # End of https://www.toptal.com/developers/gitignore/api/rust From ad73ea024ca97ac78165ee6fff5945775a4057e8 Mon Sep 17 00:00:00 2001 From: datben Date: Wed, 15 Mar 2023 21:21:31 +0100 Subject: [PATCH 2/4] init --- .gitignore | 2 +- Cargo.lock | 753 ++++++++++++++---- crates/anchor-generate-cpi-crate/Cargo.toml | 2 +- .../anchor-generate-cpi-interface/Cargo.toml | 2 +- crates/anchor-idl/Cargo.toml | 5 +- crates/anchor-idl/src/lib.rs | 2 + crates/anchor-idl/src/program.rs | 70 +- crates/anchor-idl/src/state.rs | 37 +- crates/anchor-idl/src/typedef.rs | 33 +- examples/whirlpools/Cargo.toml | 1 + examples/whirlpools/src/lib.rs | 4 +- 11 files changed, 701 insertions(+), 210 deletions(-) diff --git a/.gitignore b/.gitignore index 6088d06..b1c6cf8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,6 @@ target/ # MSVC Windows builds of rustc generate these, which store debugging information *.pdb -**/.DS_STORE +**/.DS_Store # End of https://www.toptal.com/developers/gitignore/api/rust diff --git a/Cargo.lock b/Cargo.lock index cfbcd53..1a5586e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "anchor-attribute-access-control" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9b75d05b6b4ac9d95bb6e3b786b27d3a708c4c5a87c92ffaa25bbe9ae4c5d91" +checksum = "2d5e1a413b311b039d29b61d0dbb401c9dbf04f792497ceca87593454bf6d7dd" dependencies = [ "anchor-syn", "anyhow", @@ -38,9 +38,9 @@ dependencies = [ [[package]] name = "anchor-attribute-account" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "485351a6d8157750d10d88c8e256f1bf8339262b2220ae9125aed3471309b5de" +checksum = "cca9aeaf633c6e2365fed0525dcac68610be58eee5dc69d3b86fe0b1d4b320b9" dependencies = [ "anchor-syn", "anyhow", @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "anchor-attribute-constant" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc632c540913dd051a78b00587cc47f57013d303163ddfaf4fa18717f7ccc1e0" +checksum = "788e44f9e8501dabeb6f9229da0f3268fb2ae3208912608ffaa056a72031296f" dependencies = [ "anchor-syn", "proc-macro2", @@ -64,9 +64,9 @@ dependencies = [ [[package]] name = "anchor-attribute-error" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b5bd1dcfa7f3bc22dacef233d70a9e0bee269c4ac484510662f257cba2353a1" +checksum = "ea0c4d8c7e4a2605ede6fcdced9690288b2f74e24768619a85229d57e597bc97" dependencies = [ "anchor-syn", "proc-macro2", @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "anchor-attribute-event" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6f9e6ce551ac9a177a45c99a65699a860c9e95fac68675138af1246e2591b0" +checksum = "7a3b07d5c5d87b5edc72428b447b8e9ee1143b83dd1afc6a6b1d352c6a6164d8" dependencies = [ "anchor-syn", "anyhow", @@ -87,25 +87,11 @@ dependencies = [ "syn", ] -[[package]] -name = "anchor-attribute-interface" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d104aa17418cb329ed7418b227e083d5f326a27f26ce98f5d92e33da62a5f459" -dependencies = [ - "anchor-syn", - "anyhow", - "heck 0.3.3", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "anchor-attribute-program" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6831b920b173c004ddf7ae1167d1d25e9f002ffcb1773bbc5c7ce532a4441e1" +checksum = "b22ad0445115dbea5869b1d062da49ae125abed9132fc20c33227f25e42dfa6b" dependencies = [ "anchor-syn", "anyhow", @@ -115,10 +101,10 @@ dependencies = [ ] [[package]] -name = "anchor-attribute-state" -version = "0.24.2" +name = "anchor-derive-accounts" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde147b10c71d95dc679785db0b5f3abac0091f789167aa62ac0135e2f54e8b9" +checksum = "48daeff6781ba2f02961b0ad211feb9a2de75af345d42c62b1a252fd4dfb0724" dependencies = [ "anchor-syn", "anyhow", @@ -128,13 +114,11 @@ dependencies = [ ] [[package]] -name = "anchor-derive-accounts" -version = "0.24.2" +name = "anchor-derive-space" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cde98a0e1a56046b040ff591dfda391f88917af2b6487d02b45093c05be3514" +checksum = "c4fe2886f92c4f33ec1b2b8b2b43ca1b9070cf4929e63c7eaaa09a9f2c0d5123" dependencies = [ - "anchor-syn", - "anyhow", "proc-macro2", "quote", "syn", @@ -173,6 +157,7 @@ version = "0.3.1" dependencies = [ "anchor-lang", "anchor-syn", + "bytemuck", "darling", "heck 0.4.0", "proc-macro2", @@ -183,19 +168,18 @@ dependencies = [ [[package]] name = "anchor-lang" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85dd2c5e29e20c7f4701a43724d6cd5406d0ee5694705522e43da0f26542a84" +checksum = "dbbe5d1c7c057c6d63b4f2f538a320e4a22111126c9966340c3d9490e2f15ed1" dependencies = [ "anchor-attribute-access-control", "anchor-attribute-account", "anchor-attribute-constant", "anchor-attribute-error", "anchor-attribute-event", - "anchor-attribute-interface", "anchor-attribute-program", - "anchor-attribute-state", "anchor-derive-accounts", + "anchor-derive-space", "arrayref", "base64 0.13.0", "bincode", @@ -207,19 +191,18 @@ dependencies = [ [[package]] name = "anchor-syn" -version = "0.24.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03549dc2eae0b20beba6333b14520e511822a6321cdb1760f841064a69347316" +checksum = "11cb31fe143aedb36fc41409ea072aa0b840cbea727e62eb2ff6e7b6cea036ff" dependencies = [ "anyhow", "bs58 0.3.1", "heck 0.3.3", "proc-macro2", - "proc-macro2-diagnostics", "quote", "serde", "serde_json", - "sha2", + "sha2 0.9.9", "syn", "thiserror", ] @@ -230,6 +213,97 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +[[package]] +name = "ark-bn254" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea691771ebbb28aea556c044e2e5c5227398d840cee0c34d4d20fa8eb2689e8c" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.3.3", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint", + "num-traits", + "quote", + "syn", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-std", + "digest 0.9.0", +] + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "array-bytes" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ad284aeb45c13f2fb4f084de4a420ebf447423bdf9386c0540ce33cb3ef4b8c" + [[package]] name = "arrayref" version = "0.3.6" @@ -242,17 +316,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -286,6 +349,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + [[package]] name = "blake3" version = "1.3.1" @@ -332,7 +404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ "borsh-derive", - "hashbrown", + "hashbrown 0.11.2", ] [[package]] @@ -426,9 +498,12 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -471,6 +546,49 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + [[package]] name = "crunchy" version = "0.2.2" @@ -505,7 +623,8 @@ checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core", + "rand_core 0.5.1", + "serde", "subtle", "zeroize", ] @@ -545,6 +664,17 @@ dependencies = [ "syn", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.9.0" @@ -571,19 +701,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" -[[package]] -name = "env_logger" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "feature-probe" version = "0.1.1" @@ -627,8 +744,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -648,6 +767,15 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + [[package]] name = "heck" version = "0.3.3" @@ -665,9 +793,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] @@ -693,12 +821,6 @@ dependencies = [ "hmac", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "ident_case" version = "1.0.1" @@ -706,12 +828,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] -name = "instant" -version = "0.1.12" +name = "im" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" dependencies = [ - "cfg-if", + "bitmaps", + "rand_core 0.6.4", + "rand_xoshiro", + "rayon", + "serde", + "sized-chunks", + "typenum", + "version_check", ] [[package]] @@ -729,6 +858,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.60" @@ -769,9 +907,9 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand", + "rand 0.7.3", "serde", - "sha2", + "sha2 0.9.9", "typenum", ] @@ -839,13 +977,33 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.5.7" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95af15f345b17af2efc8ead6080fb8bc376f8cec1b35277b935637595fe77498" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" dependencies = [ "libc", ] +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-derive" version = "0.3.3" @@ -857,6 +1015,16 @@ dependencies = [ "syn", ] +[[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-traits" version = "0.2.15" @@ -866,6 +1034,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "once_cell" version = "1.15.0" @@ -880,27 +1058,50 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", - "instant", "libc", "redox_syscall", "smallvec", - "winapi", + "windows-sys", +] + +[[package]] +name = "paste" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" + +[[package]] +name = "pbkdf2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216eaa586a190f0a738f2f918511eecfa90f13295abec0e457cdebcceda80cbd" +dependencies = [ + "crypto-mac", +] + +[[package]] +name = "pest" +version = "2.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cbd939b234e95d72bc393d51788aec68aeeb5d51e748ca08ff3aad58cb722f7" +dependencies = [ + "thiserror", + "ucd-trie", ] [[package]] @@ -927,19 +1128,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proc-macro2-diagnostics" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "version_check", - "yansi", -] - [[package]] name = "quote" version = "1.0.21" @@ -957,11 +1145,21 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom 0.1.16", "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.2.2", + "rand_core 0.5.1", "rand_hc", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -969,7 +1167,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "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", ] [[package]] @@ -981,13 +1189,53 @@ 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.7", +] + [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_xoshiro" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", ] [[package]] @@ -1016,13 +1264,28 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver", + "semver 1.0.14", ] [[package]] @@ -1043,12 +1306,30 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + [[package]] name = "semver" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "serde" version = "1.0.145" @@ -1102,16 +1383,35 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.5", +] + [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", + "digest 0.10.5", "keccak", - "opaque-debug", +] + +[[package]] +name = "sized-chunks" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" +dependencies = [ + "bitmaps", + "typenum", ] [[package]] @@ -1122,53 +1422,60 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "solana-frozen-abi" -version = "1.9.29" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d4fcb89eb3d0f30bd4b4a31ad1825c9d95cd638509acead00969d7601713288" +checksum = "48f7051cccdf891ac2603cdd295eb651529fe2b678b6b3af60b82dec9a9b3b06" dependencies = [ + "ahash", + "blake3", + "block-buffer 0.9.0", "bs58 0.4.0", "bv", + "byteorder", + "cc", + "either", "generic-array", + "getrandom 0.1.16", + "hashbrown 0.12.3", + "im", + "lazy_static", "log", "memmap2", - "rustc_version", + "once_cell", + "rand_core 0.6.4", + "rustc_version 0.4.0", "serde", + "serde_bytes", "serde_derive", - "sha2", + "serde_json", + "sha2 0.10.6", "solana-frozen-abi-macro", - "solana-logger", + "subtle", "thiserror", ] [[package]] name = "solana-frozen-abi-macro" -version = "1.9.29" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d63ab101db88ecccd8da34065b9097b88367e0744fdfd05cb7de87b4ede3717f" +checksum = "06395428329810ade1d2518a7e75d8a6f02d01fe548aabb60ff1ba6a2eaebbe5" dependencies = [ "proc-macro2", "quote", - "rustc_version", + "rustc_version 0.4.0", "syn", ] -[[package]] -name = "solana-logger" -version = "1.9.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1805d52fc8277a84c4803c7850c8f41471b57fb0dec7750338955ad6e43e2" -dependencies = [ - "env_logger", - "lazy_static", - "log", -] - [[package]] name = "solana-program" -version = "1.9.29" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5deafc4902425d40197f74166640300dd20b078e4ffd518c1bb56ceb7e01680" +checksum = "1ae9f0fa7db3a4e90fa0df2723ac8cbc042e579cf109cd0380bc5a8c88bed924" dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff", + "array-bytes", "base64 0.13.0", "bincode", "bitflags", @@ -1178,39 +1485,46 @@ dependencies = [ "bs58 0.4.0", "bv", "bytemuck", + "cc", "console_error_panic_hook", "console_log", "curve25519-dalek", - "getrandom 0.1.16", + "getrandom 0.2.7", "itertools", "js-sys", "lazy_static", + "libc", "libsecp256k1", "log", + "memoffset", + "num-bigint", "num-derive", "num-traits", "parking_lot", - "rand", - "rustc_version", + "rand 0.7.3", + "rand_chacha 0.2.2", + "rustc_version 0.4.0", "rustversion", "serde", "serde_bytes", "serde_derive", - "sha2", + "serde_json", + "sha2 0.10.6", "sha3", "solana-frozen-abi", "solana-frozen-abi-macro", - "solana-logger", "solana-sdk-macro", "thiserror", + "tiny-bip39", "wasm-bindgen", + "zeroize", ] [[package]] name = "solana-sdk-macro" -version = "1.9.29" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db4c93bd43c91290ad54fe6ff86179a859954f196507c4789a4876d38a62f17" +checksum = "f809319358d5da7c3a0ac08ebf4d87b21170d928dbb7260254e8f3061f7f9e0e" dependencies = [ "bs58 0.4.0", "proc-macro2", @@ -1243,12 +1557,15 @@ dependencies = [ ] [[package]] -name = "termcolor" -version = "1.1.3" +name = "synstructure" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ - "winapi-util", + "proc-macro2", + "quote", + "syn", + "unicode-xid", ] [[package]] @@ -1271,6 +1588,40 @@ dependencies = [ "syn", ] +[[package]] +name = "tiny-bip39" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d" +dependencies = [ + "anyhow", + "hmac", + "once_cell", + "pbkdf2", + "rand 0.7.3", + "rustc-hash", + "sha2 0.9.9", + "thiserror", + "unicode-normalization", + "wasm-bindgen", + "zeroize", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "toml" version = "0.5.9" @@ -1286,18 +1637,39 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "ucd-trie" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" + [[package]] name = "unicode-ident" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "version_check" version = "0.9.4" @@ -1386,47 +1758,92 @@ version = "0.3.0" dependencies = [ "anchor-gen", "anchor-lang", + "bytemuck", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows-targets" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] [[package]] -name = "winapi-util" -version = "0.1.5" +name = "windows_aarch64_gnullvm" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_aarch64_msvc" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] -name = "yansi" -version = "0.5.1" +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "zeroize" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] diff --git a/crates/anchor-generate-cpi-crate/Cargo.toml b/crates/anchor-generate-cpi-crate/Cargo.toml index 6a2644f..b009b3e 100644 --- a/crates/anchor-generate-cpi-crate/Cargo.toml +++ b/crates/anchor-generate-cpi-crate/Cargo.toml @@ -22,4 +22,4 @@ anchor-idl = { version = "0.3.0", path = "../anchor-idl" } syn = { version = "1", features = ["full"] } [dev-dependencies] -anchor-lang = "0.24.2" +anchor-lang = "0.27.0" diff --git a/crates/anchor-generate-cpi-interface/Cargo.toml b/crates/anchor-generate-cpi-interface/Cargo.toml index b2f8725..e15de98 100644 --- a/crates/anchor-generate-cpi-interface/Cargo.toml +++ b/crates/anchor-generate-cpi-interface/Cargo.toml @@ -23,4 +23,4 @@ darling = "0.14" syn = { version = "1", features = ["full"] } [dev-dependencies] -anchor-lang = "0.24.2" +anchor-lang = "0.27.0" diff --git a/crates/anchor-idl/Cargo.toml b/crates/anchor-idl/Cargo.toml index a0374c2..e4bea54 100644 --- a/crates/anchor-idl/Cargo.toml +++ b/crates/anchor-idl/Cargo.toml @@ -12,13 +12,14 @@ keywords = ["solana", "anchor"] compat-program-result = [] [dependencies] -anchor-syn = { version = "0.24.2", features = ["idl"] } +anchor-syn = { version = "0.27.0", features = ["idl"] } darling = "0.14" heck = "0.4.0" proc-macro2 = "1" quote = "1" serde_json = "1.0.81" syn = { version = "1", features = ["full"] } +bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]} [dev-dependencies] -anchor-lang = "0.24.2" +anchor-lang = "0.27.0" diff --git a/crates/anchor-idl/src/lib.rs b/crates/anchor-idl/src/lib.rs index 2e09c6a..61e4db3 100644 --- a/crates/anchor-idl/src/lib.rs +++ b/crates/anchor-idl/src/lib.rs @@ -33,6 +33,8 @@ pub fn ty_to_rust_type(ty: &IdlType) -> String { IdlType::F64 => "f64".to_string(), IdlType::U128 => "u128".to_string(), IdlType::I128 => "i128".to_string(), + IdlType::U256 => "u256".to_string(), + IdlType::I256 => "i256".to_string(), IdlType::Bytes => "Vec".to_string(), IdlType::String => "String".to_string(), IdlType::PublicKey => "Pubkey".to_string(), diff --git a/crates/anchor-idl/src/program.rs b/crates/anchor-idl/src/program.rs index 82b41a9..d238108 100644 --- a/crates/anchor-idl/src/program.rs +++ b/crates/anchor-idl/src/program.rs @@ -18,8 +18,12 @@ pub struct GeneratorOptions { pub idl_path: String, /// List of zero copy structs. pub zero_copy: Option, - /// List of `repr(packed)` structs. - pub packed: Option, + /// List of anchor legacy zero copy structs. + pub zero_copy_unsafe: Option, + /// List of `repr(C)` structs. + pub c_representation: Option, + /// List of `repr(transparent)` structs. + pub transparent_representation: Option, } fn path_list_to_string(list: Option<&PathList>) -> HashSet { @@ -38,17 +42,54 @@ impl GeneratorOptions { let idl_contents = fs::read_to_string(&path).unwrap(); let idl: anchor_syn::idl::Idl = serde_json::from_str(&idl_contents).unwrap(); - let zero_copy = path_list_to_string(self.zero_copy.as_ref()); - let packed = path_list_to_string(self.packed.as_ref()); + let zero_copy_safe = path_list_to_string(self.zero_copy.as_ref()); + + let zero_copy_unsafe = path_list_to_string(self.zero_copy_unsafe.as_ref()); + + let c_repr = path_list_to_string(self.c_representation.as_ref()); + + let transparent_repr = path_list_to_string(self.transparent_representation.as_ref()); + + let repr = c_repr + .union(&transparent_repr) + .cloned() + .collect::>(); + + let zero_copy = zero_copy_safe + .union(&zero_copy_unsafe) + .cloned() + .collect::>(); let mut struct_opts: BTreeMap = BTreeMap::new(); - let all_structs: HashSet<&String> = zero_copy.union(&packed).collect::>(); + let all_structs: HashSet<&String> = zero_copy.union(&repr).collect::>(); all_structs.into_iter().for_each(|name| { + let is_c_repr = c_repr.contains(name); + let is_transparent_repr = transparent_repr.contains(name); + + assert!(!(is_c_repr && is_transparent_repr)); + + let representation = match (is_c_repr, is_transparent_repr) { + (true, true) => panic!("cant be c and transparent representation at the same time"), + (true, false) => Some(Representation::C), + (false, true) => Some(Representation::Transparent), + (false, false) => None, + }; + + let is_zero_copy_safe = zero_copy_safe.contains(name); + let is_zero_copy_unsafe = zero_copy_unsafe.contains(name); + + let zero_copy = match (is_zero_copy_safe, is_zero_copy_unsafe) { + (true, true) => panic!("cant be safe and unsafe zero copy at the same time"), + (true, false) => Some(ZeroCopy::Safe), + (false, true) => Some(ZeroCopy::Unsafe), + (false, false) => None, + }; + struct_opts.insert( name.to_string(), StructOpts { - zero_copy: zero_copy.contains(name), - packed: packed.contains(name), + representation, + zero_copy, }, ); }); @@ -59,10 +100,21 @@ impl GeneratorOptions { #[derive(Clone, Copy, Default)] pub struct StructOpts { - pub packed: bool, - pub zero_copy: bool, + pub representation: Option, + pub zero_copy: Option, } +#[derive(Clone, Copy)] +pub enum ZeroCopy { + Unsafe, + Safe, +} + +#[derive(Clone, Copy)] +pub enum Representation { + C, + Transparent, +} pub struct Generator { pub idl: anchor_syn::idl::Idl, pub struct_opts: BTreeMap, diff --git a/crates/anchor-idl/src/state.rs b/crates/anchor-idl/src/state.rs index 4a9fa10..4df35ad 100644 --- a/crates/anchor-idl/src/state.rs +++ b/crates/anchor-idl/src/state.rs @@ -15,7 +15,7 @@ pub fn generate_account( ) -> TokenStream { let props = get_field_list_properties(defs, fields); - let derive_copy = if props.can_copy && !opts.zero_copy { + let derive_copy = if props.can_copy && !opts.zero_copy.is_some() { quote! { #[derive(Copy)] } @@ -29,24 +29,31 @@ pub fn generate_account( } else { quote! {} }; - let derive_account = if opts.zero_copy { - let repr = if opts.packed { - quote! { - #[repr(packed)] + let derive_account = if let Some(zero_copy) = opts.zero_copy { + let zero_copy_quote = match zero_copy { + crate::ZeroCopy::Unsafe => quote! { + #[account(zero_copy(unsafe))] + }, + crate::ZeroCopy::Safe => quote! { + #[account(zero_copy)] + }, + }; + if let Some(repr) = opts.representation { + match repr { + crate::Representation::C => quote! { + #zero_copy_quote + #[repr(C)] + }, + crate::Representation::Transparent => quote! { + #zero_copy_quote + #[repr(transparent)] + }, } } else { - quote! { - #[repr(C)] - } - }; - quote! { - #[account(zero_copy)] - #repr + zero_copy_quote } } else { - quote! { - #[account] - } + quote! {#[account]} }; let doc = format!(" Account: {}", account_name); diff --git a/crates/anchor-idl/src/typedef.rs b/crates/anchor-idl/src/typedef.rs index 016f960..f41e69a 100644 --- a/crates/anchor-idl/src/typedef.rs +++ b/crates/anchor-idl/src/typedef.rs @@ -82,6 +82,8 @@ pub fn get_type_properties(defs: &[IdlTypeDefinition], ty: &IdlType) -> FieldLis | IdlType::F64 | IdlType::U128 | IdlType::I128 + | IdlType::U256 + | IdlType::I256 | IdlType::PublicKey => FieldListProperties { can_copy: true, can_derive_default: true, @@ -149,19 +151,28 @@ pub fn generate_struct( } else { quote! {} }; - let derive_serializers = if opts.zero_copy { - let repr = if opts.packed { - quote! { - #[repr(packed)] + let derive_serializers = if let Some(zero_copy) = opts.zero_copy { + let zero_copy_quote = match zero_copy { + crate::ZeroCopy::Unsafe => quote! { + #[zero_copy(unsafe)] + }, + crate::ZeroCopy::Safe => quote! { + #[zero_copy] + }, + }; + if let Some(repr) = opts.representation { + match repr { + crate::Representation::C => quote! { + #zero_copy_quote + #[repr(C)] + }, + crate::Representation::Transparent => quote! { + #zero_copy_quote + #[repr(transparent)] + }, } } else { - quote! { - #[repr(C)] - } - }; - quote! { - #[zero_copy] - #repr + zero_copy_quote } } else { let derive_copy = if props.can_copy { diff --git a/examples/whirlpools/Cargo.toml b/examples/whirlpools/Cargo.toml index 1676beb..213cabc 100644 --- a/examples/whirlpools/Cargo.toml +++ b/examples/whirlpools/Cargo.toml @@ -17,4 +17,5 @@ cpi = ["no-entrypoint"] [dependencies] anchor-gen = { version = "0.3.0", path = "../../crates/anchor-gen" } +bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]} anchor-lang = ">=0.20" diff --git a/examples/whirlpools/src/lib.rs b/examples/whirlpools/src/lib.rs index 1e54e43..475cb7f 100644 --- a/examples/whirlpools/src/lib.rs +++ b/examples/whirlpools/src/lib.rs @@ -9,8 +9,8 @@ anchor_gen::generate_cpi_interface!( idl_path = "idl.json", - zero_copy(TickArray, Tick), - packed(TickArray, Tick) + zero_copy_unsafe(TickArray, Tick), + c_representation(TickArray, Tick), ); impl Default for state::TickArray { From 0699cb48765e7e1a22af8043912486bb1a7e2c8d Mon Sep 17 00:00:00 2001 From: datben Date: Wed, 15 Mar 2023 21:35:27 +0100 Subject: [PATCH 3/4] remove useless assert --- crates/anchor-idl/src/program.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/anchor-idl/src/program.rs b/crates/anchor-idl/src/program.rs index d238108..4d03768 100644 --- a/crates/anchor-idl/src/program.rs +++ b/crates/anchor-idl/src/program.rs @@ -66,8 +66,6 @@ impl GeneratorOptions { let is_c_repr = c_repr.contains(name); let is_transparent_repr = transparent_repr.contains(name); - assert!(!(is_c_repr && is_transparent_repr)); - let representation = match (is_c_repr, is_transparent_repr) { (true, true) => panic!("cant be c and transparent representation at the same time"), (true, false) => Some(Representation::C), From d5b158b8add27ad66ff9bd69f9794ec4b83e9f4a Mon Sep 17 00:00:00 2001 From: datben Date: Thu, 16 Mar 2023 20:22:45 +0100 Subject: [PATCH 4/4] add packed repr --- crates/anchor-idl/src/program.rs | 22 ++++++++++++++++------ crates/anchor-idl/src/state.rs | 11 ++++++++--- crates/anchor-idl/src/typedef.rs | 12 +++++++++--- examples/whirlpools/src/lib.rs | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/crates/anchor-idl/src/program.rs b/crates/anchor-idl/src/program.rs index 4d03768..8a1efce 100644 --- a/crates/anchor-idl/src/program.rs +++ b/crates/anchor-idl/src/program.rs @@ -24,6 +24,8 @@ pub struct GeneratorOptions { pub c_representation: Option, /// List of `repr(transparent)` structs. pub transparent_representation: Option, + /// List of `repr(packed)` structs. + pub packed_representation: Option, } fn path_list_to_string(list: Option<&PathList>) -> HashSet { @@ -50,9 +52,14 @@ impl GeneratorOptions { let transparent_repr = path_list_to_string(self.transparent_representation.as_ref()); + let packed_repr = path_list_to_string(self.packed_representation.as_ref()); + let repr = c_repr .union(&transparent_repr) .cloned() + .collect::>() + .union(&packed_repr) + .cloned() .collect::>(); let zero_copy = zero_copy_safe @@ -65,12 +72,14 @@ impl GeneratorOptions { all_structs.into_iter().for_each(|name| { let is_c_repr = c_repr.contains(name); let is_transparent_repr = transparent_repr.contains(name); - - let representation = match (is_c_repr, is_transparent_repr) { - (true, true) => panic!("cant be c and transparent representation at the same time"), - (true, false) => Some(Representation::C), - (false, true) => Some(Representation::Transparent), - (false, false) => None, + let is_packed_repr = packed_repr.contains(name); + + let representation = match (is_c_repr, is_transparent_repr, is_packed_repr) { + (true, false, false) => Some(Representation::C), + (false, true, false) => Some(Representation::Transparent), + (false, false, true) => Some(Representation::Packed), + (false, false, false) => None, + _ => panic!("a type cannot have many representation"), }; let is_zero_copy_safe = zero_copy_safe.contains(name); @@ -112,6 +121,7 @@ pub enum ZeroCopy { pub enum Representation { C, Transparent, + Packed, } pub struct Generator { pub idl: anchor_syn::idl::Idl, diff --git a/crates/anchor-idl/src/state.rs b/crates/anchor-idl/src/state.rs index 4df35ad..8b70c3d 100644 --- a/crates/anchor-idl/src/state.rs +++ b/crates/anchor-idl/src/state.rs @@ -39,15 +39,20 @@ pub fn generate_account( }, }; if let Some(repr) = opts.representation { - match repr { + let repr_quote = match repr { crate::Representation::C => quote! { - #zero_copy_quote #[repr(C)] }, crate::Representation::Transparent => quote! { - #zero_copy_quote #[repr(transparent)] }, + crate::Representation::Packed => quote! { + #[repr(packed)] + }, + }; + quote! { + #zero_copy_quote + #repr_quote } } else { zero_copy_quote diff --git a/crates/anchor-idl/src/typedef.rs b/crates/anchor-idl/src/typedef.rs index f41e69a..f959890 100644 --- a/crates/anchor-idl/src/typedef.rs +++ b/crates/anchor-idl/src/typedef.rs @@ -161,15 +161,21 @@ pub fn generate_struct( }, }; if let Some(repr) = opts.representation { - match repr { + let repr_quote = match repr { crate::Representation::C => quote! { - #zero_copy_quote #[repr(C)] }, crate::Representation::Transparent => quote! { - #zero_copy_quote + #[repr(transparent)] }, + crate::Representation::Packed => quote! { + #[repr(packed)] + }, + }; + quote! { + #zero_copy_quote + #repr_quote } } else { zero_copy_quote diff --git a/examples/whirlpools/src/lib.rs b/examples/whirlpools/src/lib.rs index 475cb7f..5d48cd3 100644 --- a/examples/whirlpools/src/lib.rs +++ b/examples/whirlpools/src/lib.rs @@ -10,7 +10,7 @@ anchor_gen::generate_cpi_interface!( idl_path = "idl.json", zero_copy_unsafe(TickArray, Tick), - c_representation(TickArray, Tick), + packed_representation(TickArray, Tick), ); impl Default for state::TickArray {