From 80e29ef6b9a081d457849a2ca42db50d7da0e37e Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 22 Oct 2020 21:44:27 -0700 Subject: [PATCH] Port SPL to solana-program and `cargo build-bpf` --- .gitignore | 2 + .travis.yml | 2 +- .travis/install-program-deps.sh | 3 +- Cargo.lock | 448 ++++++++++++------ Cargo.toml | 22 +- README.md | 63 +-- bpf-sdk-install.sh | 24 - ci/script.sh | 20 +- coverage.sh | 2 +- do.sh | 212 --------- memo/program/Cargo.toml | 9 +- memo/program/src/entrypoint.rs | 18 +- memo/program/src/lib.rs | 10 +- patch.crates-io.sh | 59 +++ shared-memory/client/Cargo.lock | 148 ++++-- shared-memory/client/Cargo.toml | 7 +- shared-memory/client/build.rs | 12 +- shared-memory/client/tests/shared-memory.rs | 6 +- shared-memory/program/Cargo.toml | 9 +- shared-memory/program/src/lib.rs | 11 +- stake-pool/cli/Cargo.toml | 14 +- stake-pool/program/Cargo.toml | 12 +- stake-pool/program/src/entrypoint.rs | 5 +- stake-pool/program/src/error.rs | 2 +- stake-pool/program/src/instruction.rs | 8 +- stake-pool/program/src/lib.rs | 11 +- stake-pool/program/src/processor.rs | 14 +- stake-pool/program/src/stake.rs | 4 +- stake-pool/program/src/state.rs | 2 +- themis/client_bn/Cargo.toml | 19 +- themis/client_bn/build.rs | 12 +- .../tests/assert_instruction_count.rs | 6 +- themis/client_ristretto/Cargo.toml | 21 +- themis/client_ristretto/build.rs | 12 +- .../tests/assert_instruction_count.rs | 6 +- themis/program_bn/Cargo.toml | 10 +- themis/program_bn/src/entrypoint.rs | 5 +- themis/program_bn/src/error.rs | 4 +- themis/program_bn/src/instruction.rs | 2 +- themis/program_bn/src/lib.rs | 11 +- themis/program_bn/src/processor.rs | 3 +- themis/program_bn/src/state.rs | 2 +- themis/program_ristretto/Cargo.toml | 11 +- themis/program_ristretto/src/entrypoint.rs | 5 +- themis/program_ristretto/src/error.rs | 4 +- themis/program_ristretto/src/instruction.rs | 2 +- themis/program_ristretto/src/lib.rs | 11 +- themis/program_ristretto/src/processor.rs | 2 +- themis/program_ristretto/src/state.rs | 2 +- token-lending/js/package.json | 4 +- token-lending/program/Cargo.toml | 10 +- token-lending/program/src/entrypoint.rs | 5 +- token-lending/program/src/error.rs | 2 +- token-lending/program/src/lib.rs | 11 +- token-lending/program/src/processor.rs | 4 +- token-swap/js/package.json | 4 +- token-swap/program/Cargo.toml | 12 +- token-swap/program/package-lock.json | 3 - token-swap/program/src/curve.rs | 2 +- token-swap/program/src/entrypoint.rs | 5 +- token-swap/program/src/error.rs | 2 +- token-swap/program/src/instruction.rs | 2 +- token-swap/program/src/lib.rs | 11 +- token-swap/program/src/processor.rs | 75 ++- token-swap/program/src/state.rs | 2 +- token/cli/Cargo.toml | 16 +- token/js/package.json | 4 +- token/perf-monitor/Cargo.lock | 148 ++++-- token/perf-monitor/Cargo.toml | 8 +- token/perf-monitor/build.rs | 12 +- .../tests/assert_instruction_count.rs | 10 +- token/program-v3/Cargo.toml | 9 +- token/program-v3/src/entrypoint.rs | 5 +- token/program-v3/src/error.rs | 2 +- token/program-v3/src/instruction.rs | 2 +- token/program-v3/src/lib.rs | 11 +- token/program-v3/src/native_mint.rs | 4 +- token/program-v3/src/processor.rs | 306 ++++++------ token/program-v3/src/state.rs | 2 +- token/program/Cargo.toml | 10 +- token/program/src/entrypoint.rs | 5 +- token/program/src/error.rs | 2 +- token/program/src/instruction.rs | 2 +- token/program/src/lib.rs | 11 +- token/program/src/native_mint.rs | 4 +- token/program/src/processor.rs | 306 ++++++------ token/program/src/state.rs | 2 +- update-solana-dependencies.sh | 41 ++ utils/test-client/Cargo.toml | 10 +- utils/test-client/src/main | 0 90 files changed, 1182 insertions(+), 1213 deletions(-) delete mode 100755 bpf-sdk-install.sh delete mode 100755 do.sh create mode 100755 patch.crates-io.sh delete mode 100644 token-swap/program/package-lock.json create mode 100755 update-solana-dependencies.sh delete mode 100644 utils/test-client/src/main diff --git a/.gitignore b/.gitignore index f37f7555..3247a14d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ bin config.json node_modules ./package-lock.json +*.so +*-dump.txt diff --git a/.travis.yml b/.travis.yml index 4085b791..a8281199 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ services: env: global: - RUST_BACKTRACE=1 - - SOLANA_VERSION=v1.4.2 + - SOLANA_VERSION=v1.4.3 jobs: include: diff --git a/.travis/install-program-deps.sh b/.travis/install-program-deps.sh index c38e8db3..f57a1567 100755 --- a/.travis/install-program-deps.sh +++ b/.travis/install-program-deps.sh @@ -22,5 +22,6 @@ node --version if [[ -n $SOLANA_VERSION ]]; then sh -c "$(curl -sSfL https://release.solana.com/$SOLANA_VERSION/install)" fi -PATH="~/.local/share/solana/install/active_release/bin:$PATH" +export PATH="~/.local/share/solana/install/active_release/bin:$PATH" solana --version +cargo build-bpf --version diff --git a/Cargo.lock b/Cargo.lock index 040c9a2e..1769296a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,9 +51,9 @@ checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" [[package]] name = "arrayvec" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "assert_matches" @@ -85,7 +85,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" dependencies = [ "addr2line", - "cfg-if", + "cfg-if 0.1.10", "libc", "miniz_oxide", "object", @@ -153,7 +153,7 @@ dependencies = [ "arrayref", "arrayvec", "cc", - "cfg-if", + "cfg-if 0.1.10", "constant_time_eq", "crypto-mac 0.8.0", "digest 0.9.0", @@ -358,6 +358,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "cgen" version = "0.1.0" @@ -443,6 +449,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "const_fn" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -473,11 +485,11 @@ checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] name = "crc32fast" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -486,21 +498,42 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "maybe-uninit", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils 0.8.0", +] + [[package]] name = "crossbeam-deque" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", + "crossbeam-epoch 0.8.2", + "crossbeam-utils 0.7.2", "maybe-uninit", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch 0.9.0", + "crossbeam-utils 0.8.0", +] + [[package]] name = "crossbeam-epoch" version = "0.8.2" @@ -508,22 +541,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ "autocfg", - "cfg-if", - "crossbeam-utils", + "cfg-if 0.1.10", + "crossbeam-utils 0.7.2", "lazy_static", "maybe-uninit", "memoffset", "scopeguard", ] +[[package]] +name = "crossbeam-epoch" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f" +dependencies = [ + "cfg-if 1.0.0", + "const_fn", + "crossbeam-utils 0.8.0", + "lazy_static", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-queue" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 0.1.10", + "crossbeam-utils 0.7.2", "maybe-uninit", ] @@ -534,7 +581,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ "autocfg", - "cfg-if", + "cfg-if 0.1.10", + "lazy_static", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "const_fn", "lazy_static", ] @@ -564,19 +623,6 @@ dependencies = [ "subtle 2.2.3", ] -[[package]] -name = "curve25519-dalek" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5" -dependencies = [ - "byteorder", - "digest 0.8.1", - "rand_core", - "subtle 2.2.3", - "zeroize", -] - [[package]] name = "curve25519-dalek" version = "2.1.0" @@ -591,6 +637,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d85653f070353a16313d0046f173f70d1aadd5b42600a14de626f0dfb3473a5" +dependencies = [ + "byteorder", + "digest 0.8.1", + "rand_core", + "subtle 2.2.3", + "zeroize", +] + [[package]] name = "derivative" version = "2.1.1" @@ -646,7 +705,7 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "dirs-sys", ] @@ -739,7 +798,7 @@ version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -795,7 +854,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "redox_syscall", "winapi 0.3.9", @@ -807,7 +866,7 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "crc32fast", "libc", "miniz_oxide", @@ -964,7 +1023,7 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "wasi", ] @@ -1315,11 +1374,11 @@ checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" [[package]] name = "libloading" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3557c9384f7f757f6d139cd3a4c62ef4e850696c16bf27924a5538c8a09717a1" +checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "winapi 0.3.9", ] @@ -1360,7 +1419,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -1443,7 +1502,7 @@ version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "fuchsia-zircon", "fuchsia-zircon-sys", "iovec", @@ -1503,7 +1562,7 @@ version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "winapi 0.3.9", ] @@ -1516,7 +1575,7 @@ checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" dependencies = [ "bitflags", "cc", - "cfg-if", + "cfg-if 0.1.10", "libc", "void", ] @@ -1623,7 +1682,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 0.1.10", "foreign-types", "lazy_static", "libc", @@ -1676,7 +1735,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "cloudabi", "libc", "redox_syscall", @@ -1691,7 +1750,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "cloudabi", "libc", "redox_syscall", @@ -1734,6 +1793,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "pin-project" version = "0.4.23" @@ -1768,9 +1836,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "ppv-lite86" @@ -1884,25 +1952,25 @@ dependencies = [ [[package]] name = "rayon" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf6960dc9a5b4ee8d3e4c5787b4a112a8818e0290a42ff664ad60692fdf2032" +checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" dependencies = [ "autocfg", - "crossbeam-deque", + "crossbeam-deque 0.8.0", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" +checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", + "crossbeam-channel 0.5.0", + "crossbeam-deque 0.8.0", + "crossbeam-utils 0.8.0", "lazy_static", "num_cpus", ] @@ -1915,9 +1983,9 @@ checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" [[package]] name = "redox_users" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ "getrandom", "redox_syscall", @@ -2015,14 +2083,14 @@ dependencies = [ [[package]] name = "rust-argon2" -version = "0.7.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" +checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19" dependencies = [ - "base64 0.11.0", + "base64 0.12.3", "blake2b_simd", "constant_time_eq", - "crossbeam-utils", + "crossbeam-utils 0.7.2", ] [[package]] @@ -2049,7 +2117,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", ] [[package]] @@ -2146,7 +2214,16 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.1", ] [[package]] @@ -2155,6 +2232,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" +dependencies = [ + "pest", +] + [[package]] name = "serde" version = "1.0.117" @@ -2250,7 +2336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1" dependencies = [ "block-buffer 0.9.0", - "cfg-if", + "cfg-if 0.1.10", "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", @@ -2301,7 +2387,7 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "redox_syscall", "winapi 0.3.9", @@ -2309,9 +2395,9 @@ dependencies = [ [[package]] name = "solana-account-decoder" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "159c9386205703ca23891e281c5c507076b966ad1e2dd6d2a5d4b5de287d3e95" +checksum = "0737ffe8737f2c01b8d50c26138a0d26fd122ee65a98d8c389152584181715cc" dependencies = [ "Inflector", "base64 0.12.3", @@ -2332,9 +2418,9 @@ dependencies = [ [[package]] name = "solana-clap-utils" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7450dac85e4304398618fd04b9cd87ec046d48ce2f277b8eff2c7218ac6e68" +checksum = "3fb8a586d806e0a7951f11a66662a4d435d05e60e8366336ec09fed967a453c1" dependencies = [ "chrono", "clap", @@ -2348,9 +2434,9 @@ dependencies = [ [[package]] name = "solana-cli-config" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a19960f5924c4973327d362f32617d3b0a5466ac4354fef10e257525a60529" +checksum = "422468fdc856153431b15342082fb4698666f145551e182e5a9af861e31d4164" dependencies = [ "dirs", "lazy_static", @@ -2362,9 +2448,9 @@ dependencies = [ [[package]] name = "solana-cli-output" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b59b015eca169721e53a47d9ebcaa892d7f8bb6f49ee277fea6959124bef250" +checksum = "1f9f6a84e7925d7e9f51bf4a823aef0aa185a453b04609464c6792a660b87b46" dependencies = [ "Inflector", "chrono", @@ -2385,9 +2471,9 @@ dependencies = [ [[package]] name = "solana-client" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d07186396103c00157a16cb38a91d002671b294dc71312330dbbcfd23bf39a" +checksum = "4210d68c774caf852d19b01f5c281e7722829f9ecd36c83a5f0dcb96430c434c" dependencies = [ "base64 0.13.0", "bincode", @@ -2398,6 +2484,7 @@ dependencies = [ "log", "rayon", "reqwest", + "semver 0.11.0", "serde", "serde_derive", "serde_json", @@ -2406,6 +2493,7 @@ dependencies = [ "solana-net-utils", "solana-sdk", "solana-transaction-status", + "solana-version", "solana-vote-program", "thiserror", "tungstenite", @@ -2414,9 +2502,9 @@ dependencies = [ [[package]] name = "solana-config-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d31450d593803698c8df43ba5cd861decfab9ea057899f8e19f50df105c306" +checksum = "be3dddd5b85283625f92e1bfa4b100e13c3941ecb472584b29afb5c5382ac09c" dependencies = [ "bincode", "chrono", @@ -2428,9 +2516,9 @@ dependencies = [ [[package]] name = "solana-crate-features" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d665c51b3065feb33f641dd1b29d476e11e14dac657725a8ba9af52e68b6618d" +checksum = "beeada39ad2aecfee8795d90ca7150389e7f958236f2630825273b9b900a7f19" dependencies = [ "backtrace", "bytes 0.4.12", @@ -2451,10 +2539,43 @@ dependencies = [ ] [[package]] -name = "solana-logger" -version = "1.4.2" +name = "solana-frozen-abi" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db07b3ea19bf351e7a38dc0a4fc4556077cfb2273ab258e48d90f4e7a83b2a6" +checksum = "63bbbf3bf442bc7e4e76b57af858030fdcb8953cdbcbc6bf3ddd4819aa38e982" +dependencies = [ + "bs58", + "bv", + "generic-array 0.14.3", + "log", + "memmap", + "rustc_version", + "serde", + "serde_derive", + "sha2 0.8.2", + "solana-frozen-abi-macro", + "solana-logger", + "thiserror", +] + +[[package]] +name = "solana-frozen-abi-macro" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb4a177d5f46025b619c83d0562e6ea302a871f98148bd7edbc82416ac76949" +dependencies = [ + "lazy_static", + "proc-macro2 1.0.19", + "quote 1.0.7", + "rustc_version", + "syn 1.0.41", +] + +[[package]] +name = "solana-logger" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f251c26d46a55bf5c3f6ef5e999e8949909eab952e19a9261e6434ebd31041" dependencies = [ "env_logger", "lazy_static", @@ -2463,9 +2584,9 @@ dependencies = [ [[package]] name = "solana-measure" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31aaf307e4bcc52b18d1fe8971bdede0a0ee0e0242ea322ae5bc2e71bb5883" +checksum = "5bacc5ec88bb53610986d49199526fd42dcad7c8b3fc795f3de5740ebff982f4" dependencies = [ "jemalloc-ctl", "jemallocator", @@ -2476,9 +2597,9 @@ dependencies = [ [[package]] name = "solana-metrics" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd1e167af8decba13acdc487cfb26ffa976e1b2fb7507baa800e9b0ae086729" +checksum = "c11d2f59d87ff29d369394654dcff3c66a898b32a351bb67a9ae9de0db2b82f2" dependencies = [ "env_logger", "gethostname", @@ -2490,9 +2611,9 @@ dependencies = [ [[package]] name = "solana-net-utils" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0e7e3f54325ee9c8c6ea941f8112ddcad5441f218144ddcf45f631b47083b46" +checksum = "49b6de7b91a2bbcf7f1ef192384f4a6a85fd9bce6eb9bbdc94740eaff33208ad" dependencies = [ "bincode", "bytes 0.4.12", @@ -2512,10 +2633,40 @@ dependencies = [ ] [[package]] -name = "solana-rayon-threadlimit" -version = "1.4.1" +name = "solana-program" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfb5a22cee0ded53e11090c6bcd963eff6d43caf49c4cda42691e94fab7ddd7d" +checksum = "9d4621f2d8ca6d7ac09c0138a02d21def0a736b70feab1f2516f5a74f1ee642f" +dependencies = [ + "bincode", + "bs58", + "bv", + "curve25519-dalek 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex", + "itertools", + "lazy_static", + "log", + "num-derive", + "num-traits", + "rand", + "rustc_version", + "rustversion", + "serde", + "serde_bytes", + "serde_derive", + "sha2 0.8.2", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-logger", + "solana-sdk-macro", + "thiserror", +] + +[[package]] +name = "solana-rayon-threadlimit" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84bac623c15acb44f571ec177b67a6434c6aa7637bdb26fe5d776aeb7f4d61ae" dependencies = [ "lazy_static", "num_cpus", @@ -2523,9 +2674,9 @@ dependencies = [ [[package]] name = "solana-remote-wallet" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c29ce4d54ae38e1aa778c49dca17c8a87e789a97f049284f15db5b9d0eb66a8" +checksum = "dbae38a11ef37f0a42267aaa8778246ab61402ec6abea352bad862dab8f3ab24" dependencies = [ "base32", "console 0.11.3", @@ -2535,7 +2686,7 @@ dependencies = [ "num-derive", "num-traits", "parking_lot 0.10.2", - "semver", + "semver 0.9.0", "solana-sdk", "thiserror", "url", @@ -2543,16 +2694,16 @@ dependencies = [ [[package]] name = "solana-runtime" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d511d1dfcf89db6783e83f9f028f139bbff357e190bd0947bd23ff1235f97558" +checksum = "8242a732a6db6227854f9bb0c2958c1f219be85989d7ca66d934033d32043c4f" dependencies = [ "bincode", "blake3", "bv", "byteorder", "bzip2", - "crossbeam-channel", + "crossbeam-channel 0.4.4", "dir-diff", "flate2", "fnv", @@ -2573,12 +2724,13 @@ dependencies = [ "serde", "serde_derive", "solana-config-program", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", "solana-measure", "solana-metrics", "solana-rayon-threadlimit", "solana-sdk", - "solana-sdk-macro-frozen-abi", "solana-secp256k1-program", "solana-stake-program", "solana-vote-program", @@ -2591,9 +2743,9 @@ dependencies = [ [[package]] name = "solana-sdk" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e8742ccdaac9ff6e7085e8eb3737858254e4691c6fcaac6b472875db2bbba0d" +checksum = "096751fdd2ec2dc3ed7146b1b14245a5b562a21b5046bf3677810a96037aff96" dependencies = [ "assert_matches", "bincode", @@ -2601,7 +2753,6 @@ dependencies = [ "bv", "byteorder", "chrono", - "curve25519-dalek 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.9.0", "ed25519-dalek", "generic-array 0.14.3", @@ -2625,17 +2776,19 @@ dependencies = [ "sha2 0.8.2", "sha3", "solana-crate-features", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", + "solana-program", "solana-sdk-macro", - "solana-sdk-macro-frozen-abi", "thiserror", ] [[package]] name = "solana-sdk-macro" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38f6c5f3b4119ffa7f75156836e5c88082e557fa978fe1f87995bd386b0d08" +checksum = "a02d89c5d8c3c098552e39ad716f8e25b1b9ce95905ad0c770c78d36e1ebcc39" dependencies = [ "bs58", "proc-macro2 1.0.19", @@ -2644,24 +2797,11 @@ dependencies = [ "syn 1.0.41", ] -[[package]] -name = "solana-sdk-macro-frozen-abi" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e47f618ad2d7af7b9c701e9cc9951681f6d6a9c754863f2ab63e1b98507e515" -dependencies = [ - "lazy_static", - "proc-macro2 1.0.19", - "quote 1.0.7", - "rustc_version", - "syn 1.0.41", -] - [[package]] name = "solana-secp256k1-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8888a924c9183f430a72e1a643648aeff105278bc39315d211bd6b6197e0a0" +checksum = "0fa9c6d939374dc10aadb4f5d918134d3388411f8bb975386cd6769afe127268" dependencies = [ "bincode", "digest 0.9.0", @@ -2674,9 +2814,9 @@ dependencies = [ [[package]] name = "solana-stake-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3780a14335d07b301128ad518876c8f4c3cb513f88e808faef3ed8a5090abc6" +checksum = "1decea030cb64647c3bee685d804344c10de071ec03f0331436c8c90b500ca27" dependencies = [ "bincode", "log", @@ -2686,18 +2826,19 @@ dependencies = [ "serde", "serde_derive", "solana-config-program", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-metrics", "solana-sdk", - "solana-sdk-macro-frozen-abi", "solana-vote-program", "thiserror", ] [[package]] name = "solana-transaction-status" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c333620a52135ae3fb203d59a4aef04b20100de3968a253a7f910f2149d42cb5" +checksum = "02023b7612aac4e16df72346a40aad78f86c14cc23ede4856e8aa9b630b9933e" dependencies = [ "Inflector", "base64 0.12.3", @@ -2719,25 +2860,26 @@ dependencies = [ [[package]] name = "solana-version" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54ff0a603c09a9b7e13136228f14d8662685065159e577644806c1f48bec1297" +checksum = "91f4abdd641e9a9251f6e6328a3b185e492ca8a532bd14f93d334718e37f08ee" dependencies = [ "log", "rustc_version", "serde", "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", "solana-runtime", "solana-sdk", - "solana-sdk-macro-frozen-abi", ] [[package]] name = "solana-vote-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595274785736cbae1f012ed1c78aebbbe2cf75720dec1e1850800c9cd64fae9b" +checksum = "b44aeb9a4169443ce3d2ee417fe61abc1067d6d842e609f3ec30e462b98fae45" dependencies = [ "bincode", "log", @@ -2746,10 +2888,11 @@ dependencies = [ "rustc_version", "serde", "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", "solana-metrics", "solana-sdk", - "solana-sdk-macro-frozen-abi", "thiserror", ] @@ -2763,7 +2906,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" name = "spl-memo" version = "1.0.9" dependencies = [ - "solana-sdk", + "solana-program", ] [[package]] @@ -2780,7 +2923,7 @@ name = "spl-shared-memory" version = "2.0.6" dependencies = [ "arrayref", - "solana-sdk", + "solana-program", ] [[package]] @@ -2795,7 +2938,7 @@ dependencies = [ "remove_dir_all", "serde", "serde_derive", - "solana-sdk", + "solana-program", "spl-token 2.0.8", "thiserror", ] @@ -2812,7 +2955,7 @@ dependencies = [ "num-derive", "num-traits", "rand", - "solana-sdk", + "solana-program", "thiserror", ] @@ -2828,7 +2971,7 @@ dependencies = [ "num-derive", "num-traits", "rand", - "solana-sdk", + "solana-program", "thiserror", ] @@ -2840,9 +2983,8 @@ dependencies = [ "num-derive", "num-traits", "num_enum", - "rand", "remove_dir_all", - "solana-sdk", + "solana-program", "thiserror", ] @@ -2886,8 +3028,7 @@ dependencies = [ "num-derive", "num-traits", "num_enum", - "rand", - "solana-sdk", + "solana-program", "thiserror", ] @@ -2898,9 +3039,8 @@ dependencies = [ "arrayref", "num-derive", "num-traits", - "rand", "remove_dir_all", - "solana-sdk", + "solana-program", "spl-token 2.0.8", "thiserror", ] @@ -2915,7 +3055,7 @@ dependencies = [ "num_enum", "rand", "remove_dir_all", - "solana-sdk", + "solana-program", "thiserror", ] @@ -2995,7 +3135,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "rand", "redox_syscall", @@ -3024,9 +3164,9 @@ dependencies = [ [[package]] name = "termios" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0fcee7b24a25675de40d5bb4de6e41b0df07bc9856295e7e2b3a3600c400c2" +checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" dependencies = [ "libc", ] @@ -3181,7 +3321,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures", ] @@ -3213,7 +3353,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09bc590ec4ba8ba87652da2068d150dcada2cfa2e07faae270a5e0409aa51351" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures", "lazy_static", "log", @@ -3268,9 +3408,9 @@ version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df720b6581784c118f0eb4310796b12b1d242a7eb95f716a8367855325c25f89" dependencies = [ - "crossbeam-deque", + "crossbeam-deque 0.7.3", "crossbeam-queue", - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures", "lazy_static", "log", @@ -3285,7 +3425,7 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93044f2d313c95ff1cb7809ce9a7a05735b012288a888b62d4434fd58c94f296" dependencies = [ - "crossbeam-utils", + "crossbeam-utils 0.7.2", "futures", "slab", "tokio-executor", @@ -3359,7 +3499,7 @@ version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "log", "tracing-core", ] @@ -3405,6 +3545,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicase" version = "2.6.0" @@ -3536,7 +3682,7 @@ version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "serde", "serde_json", "wasm-bindgen-macro", @@ -3563,7 +3709,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95f8d235a77f880bcef268d379810ea6c0af2eacfa90b1ad5af731776e0c4699" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "js-sys", "wasm-bindgen", "web-sys", diff --git a/Cargo.toml b/Cargo.toml index 147080fc..1b5162a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,33 +5,17 @@ members = [ "memo/program", "shared-memory/program", "stake-pool/program", - "themis/program_bn", - "themis/program_ristretto", "token-lending/program", "token-swap/program", "token/cli", "token/program", "token/program-v3", + "themis/program_bn", + "themis/program_ristretto", ] exclude = [ "shared-memory/client", + "token/perf-monitor", "themis/client_bn", "themis/client_ristretto", - "token/perf-monitor", ] - -# Workflow for developing against local Solana crates -# -# 0. Uncomment the below patches -# 1. Replace PATH_TO_SOLANA with your local filestem path to the Solana mono-repo -# 2. Run `cargo update` -# 3. Use `cargo` normally -# - -#[patch.crates-io] -#solana-account-decoder = {path = "PATH_TO_SOLANA/account-decoder" } -#solana-clap-utils = {path = "PATH_TO_SOLANA/clap-utils" } -#solana-cli-config = {path = "PATH_TO_SOLANA/cli-config" } -#solana-client = { path = "PATH_TO_SOLANA/client"} -#solana-logger = {path = "PATH_TO_SOLANA/logger" } -#solana-sdk = { path = "PATH_TO_SOLANA/sdk" } diff --git a/README.md b/README.md index da837690..d00af725 100644 --- a/README.md +++ b/README.md @@ -16,55 +16,54 @@ all implementations. Full documentation is available at https://spl.solana.com -## Building +## Development -These programs cannot be built directly via cargo and instead require the build -scripts located in Solana's BPF-SDK. +### Environment Setup -Download or update the BPF-SDK by running: -```bash -$ ./do.sh update +1. Install the latest Rust stable from https://rustup.rs/ +2. Install the latest Solana command-line tools from https://docs.solana.com/cli/install-solana-cli-tools + +### Build + +The normal cargo build is available for building programs against your host machine: +``` +$ cargo build ``` -To build all programs, run: -```bash -$ ./do.sh build all +To build a specific program, such as SPL Token, for the Solana BPF target: +``` +$ cd token/program +$ cargo build-bpf ``` -Or choose a specific program: +### Test + +Unit tests contained within all projects can be run with: ```bash -$ ./do.sh build +$ cargo test ``` -## Testing - -Unit tests contained within all projects can be built via: -```bash -$ ./do.sh test all +To run a specific program's tests, such as SPL Token: +``` +$ cd token/program +$ cargo test ``` -Or: -```bash -$ ./do.sh test -``` - -End-to-end testing may be performed via the per-project .js bindings. See the +Integration testing may be performed via the per-project .js bindings. See the [token program's js project](token/js) for an example. -## Clippy - -Clippy is also supported via: +### Clippy ```bash -$ ./do.sh clippy all +$ cargo clippy ``` -Or: -``` -$ ./do.sh clippy +### Coverage +```bash +$ ./coverage.sh ``` + ## Release Process - SPL programs are currently tagged and released manually. Each program is versioned independently of the others, with all new development occurring on master. Once a program is tested and deemed ready for release: @@ -73,7 +72,9 @@ master. Once a program is tested and deemed ready for release: * Increment the version number in the program's Cargo.toml * Generate a new program ID and replace in `/program-id.md` and `/src/lib.rs` - * Run `./do.sh build ` to update relevant C bindings. (Note the location of the generated `spl_.so` for attaching to the Github release.) + * Run `cargo build ` to update relevant C bindings. (Note the + location of the generated `spl_.so` for attaching to the Github + release.) * Open a PR with these version changes and merge after passing CI. ### Create Github tag diff --git a/bpf-sdk-install.sh b/bpf-sdk-install.sh deleted file mode 100755 index 37493d5b..00000000 --- a/bpf-sdk-install.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -set -e - -channel=${1:-v1.3.17} -installDir="$(dirname "$0")"/bin -cacheDir=~/.cache/solana-bpf-sdk/"$channel" - -echo "Installing $channel BPF SDK into $installDir" - -set -x - -if [[ ! -r "$cacheDir"/bpf-sdk.tar.bz2 ]]; then - mkdir -p "$cacheDir" - curl -L --retry 5 --retry-delay 2 -o "$cacheDir"/bpf-sdk.tar.bz2 \ - https://solana-sdk.s3.amazonaws.com/"$channel"/bpf-sdk.tar.bz2 -fi - -rm -rf "$installDir" -mkdir -p "$installDir" -( - cd "$installDir" - tar jxf "$cacheDir"/bpf-sdk.tar.bz2 -) -cat "$installDir"/bpf-sdk/version.txt diff --git a/ci/script.sh b/ci/script.sh index 7534a94d..da8602fd 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -34,14 +34,11 @@ export RUSTFLAGS="-D warnings" export RUSTBACKTRACE=1 _ cargo fmt --all -- --check -_ cargo +nightly clippy --workspace --all-targets -- --deny=warnings - - -# Build client libraries +_ cargo +nightly clippy -Zunstable-options --workspace --all-targets -- --deny=warnings _ cargo build +_ cargo test _ cargo run --manifest-path=utils/test-client/Cargo.toml - # # Check generated C headers # _ cargo run --manifest-path=utils/cgen/Cargo.toml # @@ -50,20 +47,11 @@ _ cargo run --manifest-path=utils/test-client/Cargo.toml # _ git diff --exit-code token-swap/program/inc/token-swap.h # _ cc token-swap/program/inc/token-swap.h -o target/token-swap.gch + # For all BPF programs for Xargo_toml in $(git ls-files -- '*/Xargo.toml'); do program_dir=$(dirname "$Xargo_toml") - ( - # Run clippy for all program crates, with the `program` feature enabled - cd $program_dir - _ cargo +nightly clippy --features=program -- --deny=warnings - ) - - _ ./do.sh build "$program_dir" - - _ ./do.sh test "$program_dir" - - _ ./do.sh dump "$program_dir" + _ cargo build-bpf --manifest-path="$program_dir"/Cargo.toml --dump done # Run client tests diff --git a/coverage.sh b/coverage.sh index 8754e781..f75214e7 100755 --- a/coverage.sh +++ b/coverage.sh @@ -56,7 +56,7 @@ for program in ${programs[@]}; do ( set -ex cd $program - cargo +nightly test --target-dir $here/target/cov --features=program + cargo +nightly test --target-dir $here/target/cov ) done diff --git a/do.sh b/do.sh deleted file mode 100755 index 9814c881..00000000 --- a/do.sh +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/env bash - -CALLER_PWD=$PWD -cd "$(dirname "$0")" - -usage() { - cat < -Supported actions: - build - build-lib - clean - clippy - doc - dump - fmt - test - update -Supported projects: - all - any directory containing a Cargo.toml file -EOF -} - -sdkDir=bin/bpf-sdk -profile=bpfel-unknown-unknown/release - -readCargoVariable() { - declare variable="$1" - declare Cargo_toml="$2" - - while read -r name equals value _; do - if [[ $name = "$variable" && $equals = = ]]; then - echo "${value//\"/}" - return - fi - done < <(cat "$Cargo_toml") - echo "Unable to locate $variable in $Cargo_toml" 1>&2 -} - -perform_action() { - set -e - # Use relative path if arg starts with "." - if [[ $2 == .* ]]; then - projectDir="$CALLER_PWD"/$2 - else - projectDir="$PWD"/$2 - fi - targetDir="$PWD"/target - features= - - crateName="$(readCargoVariable name "$projectDir/Cargo.toml")" - so_path="$targetDir/$profile" - so_name="${crateName//\-/_}" - so_name_unstripped="${so_name}_unstripped" - - if [[ -f "$projectDir"/Xargo.toml ]]; then - features="--features=program" - fi - case "$1" in - build) - if [[ -f "$projectDir"/Xargo.toml ]]; then - echo "build $crateName ($projectDir)" - "$sdkDir"/rust/build.sh "$projectDir" - cp "$so_path/${so_name}.so" "$so_path/${so_name_unstripped}.so" - "$sdkDir"/dependencies/llvm-native/bin/llvm-objcopy --strip-all "$so_path/${so_name}.so" "$so_path/${so_name}.so" - else - echo "$projectDir does not contain a program, skipping" - fi - ;; - build-lib) - ( - cd "$projectDir" - echo "build-lib $crateName ($projectDir)" - export RUSTFLAGS="${@:3}" - cargo build - ) - ;; - clean) - "$sdkDir"/rust/clean.sh "$projectDir" - ;; - clippy) - ( - cd "$projectDir" - echo "clippy $crateName ($projectDir)" - cargo +nightly clippy $features ${@:3} - ) - ;; - doc) - ( - cd "$projectDir" - echo "generating docs $crateName ($projectDir)" - cargo doc ${@:3} - ) - ;; - dump) - # Dump depends on tools that are not installed by default and must be installed manually - # - readelf - # - rustfilt - if [[ -f "$projectDir"/Xargo.toml ]]; then - if ! which rustfilt > /dev/null; then - echo "Error: rustfilt not found. It can be installed by running: cargo install rustfilt" - exit 1 - fi - if ! which readelf > /dev/null; then - if [[ $(uname) = Darwin ]]; then - echo "Error: readelf not found. It can be installed by running: brew install binutils" - else - echo "Error: readelf not found." - fi - exit 1 - fi - - ( - cd "$CALLER_PWD" - "$0" build "$2" - ) - - echo "dump $crateName ($projectDir)" - - so="$so_path/${so_name}.so" - - if [[ ! -r "$so" ]]; then - echo "Error: No dump created, cannot read $so" - exit 1 - fi - dump="$so_path/${so_name}_dump" - ( - set -x - ls -la "$so" > "${dump}_mangled.txt" - readelf -aW "$so" >>"${dump}_mangled.txt" - "$sdkDir/dependencies/llvm-native/bin/llvm-objdump" \ - -print-imm-hex \ - --source \ - --disassemble \ - "$so" \ - >> "${dump}_mangled.txt" - sed s/://g <"${dump}_mangled.txt" | rustfilt >"${dump}.txt" - ) - if [[ -f "$dump.txt" ]]; then - echo "Created $dump.txt" - else - echo "Error: No dump created" - exit 1 - fi - else - echo "$projectDir does not contain a program, skipping" - fi - ;; - fmt) - ( - cd "$projectDir" - echo "formatting $projectDir" - cargo fmt ${@:3} - ) - ;; - help) - usage - exit - ;; - test) - ( - cd "$projectDir" - echo "test $projectDir" - cargo test $features ${@:3} - ) - ;; - update) - ./bpf-sdk-install.sh - ./do.sh clean all - ;; - *) - echo "Error: Unknown command" - usage - exit - ;; - esac -} - -set -e -if [[ $1 == "update" ]]; then - perform_action "$1" - exit -else - if [[ "$#" -lt 2 ]]; then - usage - exit - fi - if [[ ! -d "$sdkDir" ]]; then - ./do.sh update - fi -fi - -if [[ $2 == "all" ]]; then - # Perform operation on all projects - for project in */program*; do - if [[ -f "$project"/Cargo.toml ]]; then - perform_action "$1" "${project%/}" ${@:3} - else - continue - fi - done -else - # Perform operation on requested project - if [[ -d $2/program ]]; then - perform_action "$1" "$2/program" "${@:3}" - else - perform_action "$1" "$2" "${@:3}" - fi -fi - -exit 0 diff --git a/memo/program/Cargo.toml b/memo/program/Cargo.toml index 8578d6de..813bc57f 100644 --- a/memo/program/Cargo.toml +++ b/memo/program/Cargo.toml @@ -1,6 +1,3 @@ - -# Note: This crate must be built using do.sh - [package] name = "spl-memo" version = "1.0.9" @@ -11,12 +8,10 @@ license = "Apache-2.0" edition = "2018" [features] -no-entrypoint = [] -program = ["solana-sdk/program"] -default = ["solana-sdk/default"] +exclude_entrypoint = [] [dependencies] -solana-sdk = { version = "1.3.17", default-features = false, optional = true } +solana-program = "1.4.3" [lib] name = "spl_memo" diff --git a/memo/program/src/entrypoint.rs b/memo/program/src/entrypoint.rs index 56adbbb8..fba0c2a8 100644 --- a/memo/program/src/entrypoint.rs +++ b/memo/program/src/entrypoint.rs @@ -1,11 +1,8 @@ -//! Program entrypoint definitions +//! Program entrypoint -#![cfg(feature = "program")] -#![cfg(not(feature = "no-entrypoint"))] - -use solana_sdk::{ - account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, program_error::ProgramError, - pubkey::Pubkey, +use solana_program::{ + account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info, + program_error::ProgramError, pubkey::Pubkey, }; use std::str::from_utf8; @@ -15,18 +12,15 @@ fn process_instruction<'a>( _accounts: &'a [AccountInfo<'a>], instruction_data: &[u8], ) -> ProgramResult { + info!("hi"); from_utf8(instruction_data).map_err(|_| ProgramError::InvalidInstructionData)?; Ok(()) } -// Pull in syscall stubs when building for non-BPF targets -#[cfg(not(target_arch = "bpf"))] -solana_sdk::program_stubs!(); - #[cfg(test)] mod tests { use super::*; - use solana_sdk::{program_error::ProgramError, pubkey::Pubkey}; + use solana_program::{program_error::ProgramError, pubkey::Pubkey}; #[test] fn test_utf8_memo() { diff --git a/memo/program/src/lib.rs b/memo/program/src/lib.rs index 56571644..85e0cabe 100644 --- a/memo/program/src/lib.rs +++ b/memo/program/src/lib.rs @@ -2,10 +2,10 @@ //! A simple program that accepts a string of encoded characters and verifies that it parses. Currently handles UTF-8. -pub mod entrypoint; +#[cfg(not(feature = "exclude_entrypoint"))] +mod entrypoint; -// Export current solana-sdk types for downstream users who may also be building with a different -// solana-sdk version -pub use solana_sdk; +// Export current sdk types for downstream users building with a different sdk version +pub use solana_program; -solana_sdk::declare_id!("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"); +solana_program::declare_id!("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"); diff --git a/patch.crates-io.sh b/patch.crates-io.sh new file mode 100755 index 00000000..697c24e1 --- /dev/null +++ b/patch.crates-io.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# +# Patches the SPL crates for developing against a local solana monorepo +# + +solana_dir=$1 +if [[ -z $solana_dir ]]; then + echo "Usage: $0 " + exit 1 +fi + +workspace_crates=( + Cargo.toml + shared-memory/client/Cargo.toml + themis/client_bn/Cargo.toml + themis/client_ristretto/Cargo.toml + token/perf-monitor/Cargo.toml +) + +if [[ ! -r "$solana_dir"/scripts/read-cargo-variable.sh ]]; then + echo "$solana_dir is not a path to the solana monorepo" + exit 1 +fi + +set -e + +solana_dir=$(cd "$solana_dir" && pwd) +cd "$(dirname "$0")" + +source "$solana_dir"/scripts/read-cargo-variable.sh +solana_ver=$(readCargoVariable version "$solana_dir"/sdk/Cargo.toml) + +echo "Patching in $solana_ver from $solana_dir" +echo +for crate in "${workspace_crates[@]}"; do + if grep -q '\[patch.crates-io\]' "$crate"; then + echo "$crate is already patched" + else + cat >> "$crate" < Self { - let swap_key = pubkey_rand(); + let swap_key = Pubkey::new_unique(); let swap_account = Account::new(0, SwapInfo::get_packed_len(), &SWAP_PROGRAM_ID); let (authority_key, nonce) = Pubkey::find_program_address(&[&swap_key.to_bytes()[..]], &SWAP_PROGRAM_ID); @@ -886,6 +882,7 @@ mod tests { panic!("Could not find matching swap token account"); } + #[allow(clippy::too_many_arguments)] pub fn swap( &mut self, user_key: &Pubkey, @@ -956,6 +953,7 @@ mod tests { Ok(()) } + #[allow(clippy::too_many_arguments)] pub fn deposit( &mut self, depositor_key: &Pubkey, @@ -1036,6 +1034,7 @@ mod tests { ) } + #[allow(clippy::too_many_arguments)] pub fn withdraw( &mut self, user_key: &Pubkey, @@ -1111,10 +1110,6 @@ mod tests { Rent::default().minimum_balance(SplAccount::get_packed_len()) } - fn pubkey_rand() -> Pubkey { - Pubkey::new(&rand::random::<[u8; 32]>()) - } - fn do_process_instruction( instruction: Instruction, accounts: Vec<&mut Account>, @@ -1164,7 +1159,7 @@ mod tests { account_owner_key: &Pubkey, amount: u64, ) -> (Pubkey, Account) { - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = Account::new( account_minimum_balance(), SplAccount::get_packed_len(), @@ -1212,7 +1207,7 @@ mod tests { authority_key: &Pubkey, freeze_authority: Option<&Pubkey>, ) -> (Pubkey, Account) { - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = Account::new( mint_minimum_balance(), SplMint::get_packed_len(), @@ -1231,9 +1226,9 @@ mod tests { #[test] fn test_token_program_id_error() { - let swap_key = pubkey_rand(); - let mut mint = (pubkey_rand(), Account::default()); - let mut destination = (pubkey_rand(), Account::default()); + let swap_key = Pubkey::new_unique(); + let mut mint = (Pubkey::new_unique(), Account::default()); + let mut destination = (Pubkey::new_unique(), Account::default()); let token_program = (TOKEN_PROGRAM_ID, Account::default()); let (authority_key, nonce) = Pubkey::find_program_address(&[&swap_key.to_bytes()[..]], &SWAP_PROGRAM_ID); @@ -1260,7 +1255,7 @@ mod tests { #[test] fn test_initialize() { - let user_key = pubkey_rand(); + let user_key = Pubkey::new_unique(); let trade_fee_numerator = 1; let trade_fee_denominator = 2; let owner_trade_fee_numerator = 1; @@ -1680,7 +1675,7 @@ mod tests { // wrong token program id { - let wrong_program_id = pubkey_rand(); + let wrong_program_id = Pubkey::new_unique(); assert_eq!( Err(ProgramError::InvalidAccountData), do_process_instruction( @@ -1784,8 +1779,8 @@ mod tests { #[test] fn test_deposit() { - let user_key = pubkey_rand(); - let depositor_key = pubkey_rand(); + let user_key = Pubkey::new_unique(); + let depositor_key = Pubkey::new_unique(); let trade_fee_numerator = 1; let trade_fee_denominator = 2; let owner_trade_fee_numerator = 1; @@ -2059,7 +2054,7 @@ mod tests { pool_key, mut pool_account, ) = accounts.setup_token_accounts(&user_key, &depositor_key, deposit_a, deposit_b, 0); - let wrong_key = pubkey_rand(); + let wrong_key = Pubkey::new_unique(); assert_eq!( Err(ProgramError::InvalidAccountData), do_process_instruction( @@ -2108,7 +2103,7 @@ mod tests { let old_a_key = accounts.token_a_key; let old_a_account = accounts.token_a_account; - accounts.token_a_key = token_a_key.clone(); + accounts.token_a_key = token_a_key; accounts.token_a_account = token_a_account.clone(); // wrong swap token a account @@ -2134,7 +2129,7 @@ mod tests { let old_b_key = accounts.token_b_key; let old_b_account = accounts.token_b_account; - accounts.token_b_key = token_b_key.clone(); + accounts.token_b_key = token_b_key; accounts.token_b_account = token_b_account.clone(); // wrong swap token b account @@ -2314,7 +2309,7 @@ mod tests { #[test] fn test_withdraw() { - let user_key = pubkey_rand(); + let user_key = Pubkey::new_unique(); let trade_fee_numerator = 1; let trade_fee_denominator = 2; let owner_trade_fee_numerator = 1; @@ -2336,7 +2331,7 @@ mod tests { }), }; - let withdrawer_key = pubkey_rand(); + let withdrawer_key = Pubkey::new_unique(); let initial_a = token_a_amount / 10; let initial_b = token_b_amount / 10; let initial_pool = swap_curve.calculator.new_pool_supply() / 10; @@ -2638,7 +2633,7 @@ mod tests { initial_b, withdraw_amount, ); - let wrong_key = pubkey_rand(); + let wrong_key = Pubkey::new_unique(); assert_eq!( Err(ProgramError::InvalidAccountData), do_process_instruction( @@ -2695,7 +2690,7 @@ mod tests { let old_a_key = accounts.token_a_key; let old_a_account = accounts.token_a_account; - accounts.token_a_key = token_a_key.clone(); + accounts.token_a_key = token_a_key; accounts.token_a_account = token_a_account.clone(); // wrong swap token a account @@ -2721,7 +2716,7 @@ mod tests { let old_b_key = accounts.token_b_key; let old_b_account = accounts.token_b_account; - accounts.token_b_key = token_b_key.clone(); + accounts.token_b_key = token_b_key; accounts.token_b_account = token_b_account.clone(); // wrong swap token b account @@ -2955,7 +2950,7 @@ mod tests { mut _pool_account, ) = accounts.setup_token_accounts(&user_key, &withdrawer_key, 0, 0, 0); - let pool_fee_key = accounts.pool_fee_key.clone(); + let pool_fee_key = accounts.pool_fee_key; let mut pool_fee_account = accounts.pool_fee_account.clone(); let fee_account = Processor::unpack_token_account(&pool_fee_account.data).unwrap(); let pool_fee_amount = fee_account.amount; @@ -3006,8 +3001,8 @@ mod tests { } fn check_valid_swap_curve(curve_type: CurveType, calculator: Box) { - let user_key = pubkey_rand(); - let swapper_key = pubkey_rand(); + let user_key = Pubkey::new_unique(); + let swapper_key = Pubkey::new_unique(); let token_a_amount = 1000; let token_b_amount = 5000; @@ -3177,8 +3172,8 @@ mod tests { #[test] fn test_invalid_swap() { - let user_key = pubkey_rand(); - let swapper_key = pubkey_rand(); + let user_key = Pubkey::new_unique(); + let swapper_key = Pubkey::new_unique(); let trade_fee_numerator = 1; let trade_fee_denominator = 4; let owner_trade_fee_numerator = 1; @@ -3206,8 +3201,8 @@ mod tests { let initial_b = token_b_amount / 5; let minimum_b_amount = initial_b / 2; - let swap_token_a_key = accounts.token_a_key.clone(); - let swap_token_b_key = accounts.token_b_key.clone(); + let swap_token_a_key = accounts.token_a_key; + let swap_token_b_key = accounts.token_b_key; // swap not initialized { @@ -3280,7 +3275,7 @@ mod tests { _pool_key, _pool_account, ) = accounts.setup_token_accounts(&user_key, &swapper_key, initial_a, initial_b, 0); - let wrong_program_id = pubkey_rand(); + let wrong_program_id = Pubkey::new_unique(); assert_eq!( Err(ProgramError::InvalidAccountData), do_process_instruction( @@ -3572,7 +3567,7 @@ mod tests { ); } - // slippage exceeeded: minimum out amount too high + // slippage exceeded: minimum out amount too high { let ( token_a_key, diff --git a/token-swap/program/src/state.rs b/token-swap/program/src/state.rs index 7b648fed..b2041522 100644 --- a/token-swap/program/src/state.rs +++ b/token-swap/program/src/state.rs @@ -2,7 +2,7 @@ use crate::curve::SwapCurve; use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; -use solana_sdk::{ +use solana_program::{ program_error::ProgramError, program_pack::{IsInitialized, Pack, Sealed}, pubkey::Pubkey, diff --git a/token/cli/Cargo.toml b/token/cli/Cargo.toml index 3b65eae3..6fabfd26 100644 --- a/token/cli/Cargo.toml +++ b/token/cli/Cargo.toml @@ -12,14 +12,14 @@ version = "2.0.3" clap = "2.33.3" console = "0.13.0" serde_json = "1.0.59" -solana-account-decoder = { version = "=1.4.1" } -solana-clap-utils = { version = "=1.4.1"} -solana-cli-config = { version = "=1.4.2" } -solana-cli-output = { version = "=1.4.1" } -solana-client = { version = "=1.4.1" } -solana-logger = { version = "=1.4.2" } -solana-sdk = { version = "=1.4.1" } -spl-token = { version = "2.0", path="../program" } +solana-account-decoder = "1.4.3" +solana-clap-utils = "1.4.3" +solana-cli-config = "1.4.3" +solana-cli-output = "1.4.3" +solana-client = "1.4.3" +solana-logger = "1.4.3" +solana-sdk = "1.4.3" +spl-token = { version = "2.0", path="../program", features = [ "exclude_entrypoint" ] } [[bin]] name = "spl-token" diff --git a/token/js/package.json b/token/js/package.json index 2741616c..6bbedd62 100644 --- a/token/js/package.json +++ b/token/js/package.json @@ -31,13 +31,13 @@ "flow": "flow", "flow:watch": "watch 'flow' . --wait=1 --ignoreDirectoryPattern=/doc/", "lint:watch": "watch 'npm run lint:fix' . --wait=1", - "build:program": "rm client/util/store/config.json; ../../do.sh build token", + "build:program": "rm -f client/util/store/config.json; cargo build-bpf --manifest-path ../program/Cargo.toml", "cluster:localnet": "rm -f .env", "cluster:devnet": "cp cluster-devnet.env .env", "cluster:testnet": "cp cluster-testnet.env .env", "cluster:mainnet-beta": "cp cluster-mainnet-beta.env .env", "localnet:update": "solana-localnet update", - "localnet:up": "rm client/util/store/config.json; set -x; solana-localnet down; set -e; solana-localnet up", + "localnet:up": "rm -f client/util/store/config.json; set -x; solana-localnet down; set -e; solana-localnet up", "localnet:down": "solana-localnet down", "localnet:logs": "solana-localnet logs -f", "pretty": "prettier --check '{,cli*/**/}*.[jt]s'", diff --git a/token/perf-monitor/Cargo.lock b/token/perf-monitor/Cargo.lock index e5c4fd3f..e00e0027 100644 --- a/token/perf-monitor/Cargo.lock +++ b/token/perf-monitor/Cargo.lock @@ -1755,9 +1755,9 @@ dependencies = [ [[package]] name = "solana-bpf-loader-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4e65edb39170c8cba00256a2ae041c28bbc97cf4add0173543ab0a9893fc91b" +checksum = "ffe0627cc4ef87bb00a8691fe7c6bb7eec9efde660c5b02257daf20ccef8286a" dependencies = [ "bincode", "byteorder", @@ -1772,9 +1772,9 @@ dependencies = [ [[package]] name = "solana-config-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d31450d593803698c8df43ba5cd861decfab9ea057899f8e19f50df105c306" +checksum = "be3dddd5b85283625f92e1bfa4b100e13c3941ecb472584b29afb5c5382ac09c" dependencies = [ "bincode", "chrono", @@ -1786,9 +1786,9 @@ dependencies = [ [[package]] name = "solana-crate-features" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d665c51b3065feb33f641dd1b29d476e11e14dac657725a8ba9af52e68b6618d" +checksum = "beeada39ad2aecfee8795d90ca7150389e7f958236f2630825273b9b900a7f19" dependencies = [ "backtrace", "bytes 0.4.12", @@ -1809,10 +1809,43 @@ dependencies = [ ] [[package]] -name = "solana-logger" -version = "1.4.1" +name = "solana-frozen-abi" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa91a8812e60bcfdaffaf0d7202a6fb55b64e19a144c313d208829634c69544c" +checksum = "63bbbf3bf442bc7e4e76b57af858030fdcb8953cdbcbc6bf3ddd4819aa38e982" +dependencies = [ + "bs58", + "bv", + "generic-array 0.14.4", + "log", + "memmap", + "rustc_version", + "serde", + "serde_derive", + "sha2", + "solana-frozen-abi-macro", + "solana-logger", + "thiserror", +] + +[[package]] +name = "solana-frozen-abi-macro" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb4a177d5f46025b619c83d0562e6ea302a871f98148bd7edbc82416ac76949" +dependencies = [ + "lazy_static", + "proc-macro2 1.0.19", + "quote 1.0.6", + "rustc_version", + "syn 1.0.39", +] + +[[package]] +name = "solana-logger" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f251c26d46a55bf5c3f6ef5e999e8949909eab952e19a9261e6434ebd31041" dependencies = [ "env_logger", "lazy_static", @@ -1821,9 +1854,9 @@ dependencies = [ [[package]] name = "solana-measure" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31aaf307e4bcc52b18d1fe8971bdede0a0ee0e0242ea322ae5bc2e71bb5883" +checksum = "5bacc5ec88bb53610986d49199526fd42dcad7c8b3fc795f3de5740ebff982f4" dependencies = [ "jemalloc-ctl", "jemallocator", @@ -1834,9 +1867,9 @@ dependencies = [ [[package]] name = "solana-metrics" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd1e167af8decba13acdc487cfb26ffa976e1b2fb7507baa800e9b0ae086729" +checksum = "c11d2f59d87ff29d369394654dcff3c66a898b32a351bb67a9ae9de0db2b82f2" dependencies = [ "env_logger", "gethostname", @@ -1847,10 +1880,40 @@ dependencies = [ ] [[package]] -name = "solana-rayon-threadlimit" -version = "1.4.1" +name = "solana-program" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfb5a22cee0ded53e11090c6bcd963eff6d43caf49c4cda42691e94fab7ddd7d" +checksum = "9d4621f2d8ca6d7ac09c0138a02d21def0a736b70feab1f2516f5a74f1ee642f" +dependencies = [ + "bincode", + "bs58", + "bv", + "curve25519-dalek 2.1.0", + "hex", + "itertools", + "lazy_static", + "log", + "num-derive", + "num-traits", + "rand", + "rustc_version", + "rustversion", + "serde", + "serde_bytes", + "serde_derive", + "sha2", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-logger", + "solana-sdk-macro", + "thiserror", +] + +[[package]] +name = "solana-rayon-threadlimit" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84bac623c15acb44f571ec177b67a6434c6aa7637bdb26fe5d776aeb7f4d61ae" dependencies = [ "lazy_static", "num_cpus", @@ -1858,9 +1921,9 @@ dependencies = [ [[package]] name = "solana-runtime" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d511d1dfcf89db6783e83f9f028f139bbff357e190bd0947bd23ff1235f97558" +checksum = "8242a732a6db6227854f9bb0c2958c1f219be85989d7ca66d934033d32043c4f" dependencies = [ "bincode", "blake3", @@ -1888,12 +1951,13 @@ dependencies = [ "serde", "serde_derive", "solana-config-program", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", "solana-measure", "solana-metrics", "solana-rayon-threadlimit", "solana-sdk", - "solana-sdk-macro-frozen-abi", "solana-secp256k1-program", "solana-stake-program", "solana-vote-program", @@ -1906,9 +1970,9 @@ dependencies = [ [[package]] name = "solana-sdk" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e8742ccdaac9ff6e7085e8eb3737858254e4691c6fcaac6b472875db2bbba0d" +checksum = "096751fdd2ec2dc3ed7146b1b14245a5b562a21b5046bf3677810a96037aff96" dependencies = [ "assert_matches", "bincode", @@ -1916,7 +1980,6 @@ dependencies = [ "bv", "byteorder", "chrono", - "curve25519-dalek 2.1.0", "digest 0.9.0", "ed25519-dalek", "generic-array 0.14.4", @@ -1940,17 +2003,19 @@ dependencies = [ "sha2", "sha3", "solana-crate-features", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", + "solana-program", "solana-sdk-macro", - "solana-sdk-macro-frozen-abi", "thiserror", ] [[package]] name = "solana-sdk-macro" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38f6c5f3b4119ffa7f75156836e5c88082e557fa978fe1f87995bd386b0d08" +checksum = "a02d89c5d8c3c098552e39ad716f8e25b1b9ce95905ad0c770c78d36e1ebcc39" dependencies = [ "bs58", "proc-macro2 1.0.19", @@ -1959,24 +2024,11 @@ dependencies = [ "syn 1.0.39", ] -[[package]] -name = "solana-sdk-macro-frozen-abi" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e47f618ad2d7af7b9c701e9cc9951681f6d6a9c754863f2ab63e1b98507e515" -dependencies = [ - "lazy_static", - "proc-macro2 1.0.19", - "quote 1.0.6", - "rustc_version", - "syn 1.0.39", -] - [[package]] name = "solana-secp256k1-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8888a924c9183f430a72e1a643648aeff105278bc39315d211bd6b6197e0a0" +checksum = "0fa9c6d939374dc10aadb4f5d918134d3388411f8bb975386cd6769afe127268" dependencies = [ "bincode", "digest 0.9.0", @@ -1989,9 +2041,9 @@ dependencies = [ [[package]] name = "solana-stake-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3780a14335d07b301128ad518876c8f4c3cb513f88e808faef3ed8a5090abc6" +checksum = "1decea030cb64647c3bee685d804344c10de071ec03f0331436c8c90b500ca27" dependencies = [ "bincode", "log", @@ -2001,18 +2053,19 @@ dependencies = [ "serde", "serde_derive", "solana-config-program", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-metrics", "solana-sdk", - "solana-sdk-macro-frozen-abi", "solana-vote-program", "thiserror", ] [[package]] name = "solana-vote-program" -version = "1.4.1" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595274785736cbae1f012ed1c78aebbbe2cf75720dec1e1850800c9cd64fae9b" +checksum = "b44aeb9a4169443ce3d2ee417fe61abc1067d6d842e609f3ec30e462b98fae45" dependencies = [ "bincode", "log", @@ -2021,10 +2074,11 @@ dependencies = [ "rustc_version", "serde", "serde_derive", + "solana-frozen-abi", + "solana-frozen-abi-macro", "solana-logger", "solana-metrics", "solana-sdk", - "solana-sdk-macro-frozen-abi", "thiserror", ] @@ -2061,7 +2115,7 @@ dependencies = [ "num-traits", "num_enum", "remove_dir_all", - "solana-sdk", + "solana-program", "thiserror", ] diff --git a/token/perf-monitor/Cargo.toml b/token/perf-monitor/Cargo.toml index 327d53f7..92560c42 100644 --- a/token/perf-monitor/Cargo.toml +++ b/token/perf-monitor/Cargo.toml @@ -9,8 +9,8 @@ edition = "2018" [dev-dependencies] rand = { version = "0.7.0"} -spl-token = { path = "../program" } -solana-runtime = { version = "1.3.17" } -solana-sdk = { version = "1.3.17" } -solana-bpf-loader-program = { version = "1.3.17" } +spl-token = { path = "../program", features = [ "exclude_entrypoint" ] } +solana-runtime = "1.4.3" +solana-sdk = "1.4.3" +solana-bpf-loader-program = "1.4.3" solana_rbpf = "=0.1.32" diff --git a/token/perf-monitor/build.rs b/token/perf-monitor/build.rs index d64810ac..e24ba228 100644 --- a/token/perf-monitor/build.rs +++ b/token/perf-monitor/build.rs @@ -1,12 +1,10 @@ -use std::{fs::canonicalize, process::Command}; +use std::process::Command; fn main() { - println!("cargo:warning=(not a warning) Building SPL Token shared object"); - Command::new(canonicalize("../../do.sh").unwrap()) - .current_dir("../..") - .arg("build") - .arg("token/program") + println!("cargo:warning=(not a warning) Building BPF token program"); + Command::new("cargo") + .arg("build-bpf") .status() - .expect("Failed to build token program") + .expect("Failed to build BPF token program") .success(); } diff --git a/token/perf-monitor/tests/assert_instruction_count.rs b/token/perf-monitor/tests/assert_instruction_count.rs index 02c9924f..ad6c08a8 100644 --- a/token/perf-monitor/tests/assert_instruction_count.rs +++ b/token/perf-monitor/tests/assert_instruction_count.rs @@ -74,15 +74,15 @@ fn run_program( #[test] fn assert_instruction_count() { - let program_id = Pubkey::new_rand(); - let source_key = Pubkey::new_rand(); + let program_id = Pubkey::new_unique(); + let source_key = Pubkey::new_unique(); let source_account = SolanaAccount::new_ref(u64::MAX, Account::get_packed_len(), &program_id); - let destination_key = Pubkey::new_rand(); + let destination_key = Pubkey::new_unique(); let destination_account = SolanaAccount::new_ref(u64::MAX, Account::get_packed_len(), &program_id); - let owner_key = Pubkey::new_rand(); + let owner_key = Pubkey::new_unique(); let owner_account = RefCell::new(SolanaAccount::default()); - let mint_key = Pubkey::new_rand(); + let mint_key = Pubkey::new_unique(); let mint_account = SolanaAccount::new_ref(0, Mint::get_packed_len(), &program_id); let rent_key = rent::id(); let rent_account = RefCell::new(rent::create_account(42, &Rent::default())); diff --git a/token/program-v3/Cargo.toml b/token/program-v3/Cargo.toml index db3456f1..f26398c1 100644 --- a/token/program-v3/Cargo.toml +++ b/token/program-v3/Cargo.toml @@ -1,6 +1,3 @@ - -# Note: This crate must be built using do.sh - [package] name = "spl-token-v3" version = "3.0.0" @@ -12,15 +9,13 @@ edition = "2018" exclude = ["js/**"] [features] -no-entrypoint = [] -program = ["solana-sdk/program"] -default = ["solana-sdk/default"] +exclude_entrypoint = [] [dependencies] num-derive = "0.3" num-traits = "0.2" remove_dir_all = "=0.5.0" -solana-sdk = { version = "1.3.17", default-features = false, optional = true } +solana-program = "1.4.3" thiserror = "1.0" arrayref = "0.3.6" num_enum = "0.5.1" diff --git a/token/program-v3/src/entrypoint.rs b/token/program-v3/src/entrypoint.rs index b5594ca8..b2555132 100644 --- a/token/program-v3/src/entrypoint.rs +++ b/token/program-v3/src/entrypoint.rs @@ -1,10 +1,7 @@ //! Program entrypoint -#![cfg(feature = "program")] -#![cfg(not(feature = "no-entrypoint"))] - use crate::{error::TokenError, processor::Processor}; -use solana_sdk::{ +use solana_program::{ account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, program_error::PrintProgramError, pubkey::Pubkey, }; diff --git a/token/program-v3/src/error.rs b/token/program-v3/src/error.rs index e56fde6b..3a1591fa 100644 --- a/token/program-v3/src/error.rs +++ b/token/program-v3/src/error.rs @@ -1,7 +1,7 @@ //! Error types use num_derive::FromPrimitive; -use solana_sdk::{decode_error::DecodeError, program_error::ProgramError}; +use solana_program::{decode_error::DecodeError, program_error::ProgramError}; use thiserror::Error; /// Errors that may be returned by the Token program. diff --git a/token/program-v3/src/instruction.rs b/token/program-v3/src/instruction.rs index ae01523e..e6f15b7d 100644 --- a/token/program-v3/src/instruction.rs +++ b/token/program-v3/src/instruction.rs @@ -1,7 +1,7 @@ //! Instruction types use crate::error::TokenError; -use solana_sdk::{ +use solana_program::{ instruction::{AccountMeta, Instruction}, program_error::ProgramError, program_option::COption, diff --git a/token/program-v3/src/lib.rs b/token/program-v3/src/lib.rs index d251bb55..65804362 100644 --- a/token/program-v3/src/lib.rs +++ b/token/program-v3/src/lib.rs @@ -3,16 +3,17 @@ //! An ERC20-like Token program for the Solana blockchain -pub mod entrypoint; pub mod error; pub mod instruction; pub mod native_mint; pub mod processor; pub mod state; -// Export current solana-sdk types for downstream users who may also be building with a different -// solana-sdk version -pub use solana_sdk; +#[cfg(not(feature = "exclude_entrypoint"))] +pub mod entrypoint; + +// Export current sdk types for downstream users building with a different sdk version +pub use solana_program; /// Convert the UI representation of a token amount (using the decimals field defined in its mint) /// to the raw amount @@ -25,4 +26,4 @@ pub fn amount_to_ui_amount(amount: u64, decimals: u8) -> f64 { amount as f64 / 10_usize.pow(decimals as u32) as f64 } -solana_sdk::declare_id!("TokenKEGQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); +solana_program::declare_id!("TokenKEGQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); diff --git a/token/program-v3/src/native_mint.rs b/token/program-v3/src/native_mint.rs index e8bf5198..9ed668e3 100644 --- a/token/program-v3/src/native_mint.rs +++ b/token/program-v3/src/native_mint.rs @@ -4,12 +4,12 @@ pub const DECIMALS: u8 = 9; // The Mint for native SOL Token accounts -solana_sdk::declare_id!("So11111111111111111111111111111111111111113"); +solana_program::declare_id!("So11111111111111111111111111111111111111113"); #[cfg(test)] mod tests { use super::*; - use solana_sdk::native_token::*; + use solana_program::native_token::*; #[test] fn test_decimals() { diff --git a/token/program-v3/src/processor.rs b/token/program-v3/src/processor.rs index dd662439..b2b01243 100644 --- a/token/program-v3/src/processor.rs +++ b/token/program-v3/src/processor.rs @@ -1,14 +1,12 @@ //! Program state processor -#![cfg(feature = "program")] - use crate::{ error::TokenError, instruction::{is_valid_signer_index, AuthorityType, TokenInstruction, MAX_SIGNERS}, state::{Account, AccountState, Mint, Multisig}, }; use num_traits::FromPrimitive; -use solana_sdk::{ +use solana_program::{ account_info::{next_account_info, AccountInfo}, decode_error::DecodeError, entrypoint::ProgramResult, @@ -779,23 +777,15 @@ impl PrintProgramError for TokenError { } } -// Pull in syscall stubs when building for non-BPF targets -#[cfg(not(target_arch = "bpf"))] -solana_sdk::program_stubs!(); - #[cfg(test)] mod tests { use super::*; use crate::instruction::*; - use solana_sdk::{ + use solana_program::{ account::Account as SolanaAccount, account_info::create_is_signer_account_infos, clock::Epoch, instruction::Instruction, sysvar::rent, }; - fn pubkey_rand() -> Pubkey { - Pubkey::new(&rand::random::<[u8; 32]>()) - } - fn do_process_instruction( instruction: Instruction, accounts: Vec<&mut SolanaAccount>, @@ -967,11 +957,11 @@ mod tests { #[test] fn test_initialize_mint() { - let program_id = pubkey_rand(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(42, Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut mint2_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -1015,12 +1005,12 @@ mod tests { #[test] fn test_initialize_mint_account() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new(42, Account::get_packed_len(), &program_id); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -1091,46 +1081,46 @@ mod tests { #[test] fn test_transfer_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let mut account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let mut account2_info: AccountInfo = (&account2_key, false, &mut account2_account).into(); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account3_info: AccountInfo = (&account3_key, false, &mut account3_account).into(); - let account4_key = pubkey_rand(); + let account4_key = Pubkey::new_unique(); let mut account4_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account4_info: AccountInfo = (&account4_key, true, &mut account4_account).into(); - let multisig_key = pubkey_rand(); + let multisig_key = Pubkey::new_unique(); let mut multisig_account = SolanaAccount::new( multisig_minimum_balance(), Multisig::get_packed_len(), &program_id, ); let multisig_info: AccountInfo = (&multisig_key, true, &mut multisig_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, false, &mut mint_account).into(); @@ -1398,41 +1388,41 @@ mod tests { #[test] fn test_transfer() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); - let mismatch_key = pubkey_rand(); + let mismatch_key = Pubkey::new_unique(); let mut mismatch_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut rent_sysvar = rent_sysvar(); // create mint @@ -1728,7 +1718,7 @@ mod tests { // This is probably wrong but transactions in the wild have been observed to do this so // this behavior is now part of the token ABI { - let system_account_key = pubkey_rand(); + let system_account_key = Pubkey::new_unique(); let mut system_account = SolanaAccount::new(1, 0, &Pubkey::default()); let instruction = transfer( @@ -1897,16 +1887,16 @@ mod tests { #[test] fn test_mintable_token_with_zero_supply() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -1948,7 +1938,7 @@ mod tests { vec![&mut mint_account, &mut account_account, &mut owner_account], ) .unwrap(); - let _ = Mint::unpack(&mut mint_account.data).unwrap(); + let _ = Mint::unpack(&mint_account.data).unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); assert_eq!(account.amount, 42); @@ -1970,7 +1960,7 @@ mod tests { ) ); - let _ = Mint::unpack(&mut mint_account.data).unwrap(); + let _ = Mint::unpack(&mint_account.data).unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); assert_eq!(account.amount, 42); @@ -1989,46 +1979,46 @@ mod tests { vec![&mut mint_account, &mut account_account, &mut owner_account], ) .unwrap(); - let _ = Mint::unpack(&mut mint_account.data).unwrap(); + let _ = Mint::unpack(&mint_account.data).unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); assert_eq!(account.amount, 84); } #[test] fn test_approve_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account2_info: AccountInfo = (&account2_key, false, &mut account2_account).into(); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account3_info: AccountInfo = (&account3_key, true, &mut account3_account).into(); - let multisig_key = pubkey_rand(); + let multisig_key = Pubkey::new_unique(); let mut multisig_account = SolanaAccount::new( multisig_minimum_balance(), Multisig::get_packed_len(), &program_id, ); let multisig_info: AccountInfo = (&multisig_key, true, &mut multisig_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, false, &mut mint_account).into(); @@ -2207,26 +2197,26 @@ mod tests { #[test] fn test_approve() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -2412,16 +2402,16 @@ mod tests { #[test] fn test_set_authority_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -2515,28 +2505,28 @@ mod tests { #[test] fn test_set_authority() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let owner3_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner3_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut mint2_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -2854,18 +2844,18 @@ mod tests { #[test] fn test_mint_to_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -2950,40 +2940,40 @@ mod tests { #[test] fn test_mint_to() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let mismatch_key = pubkey_rand(); + let mismatch_key = Pubkey::new_unique(); let mut mismatch_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); - let uninitialized_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); + let uninitialized_key = Pubkey::new_unique(); let mut uninitialized_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), @@ -3153,18 +3143,18 @@ mod tests { #[test] fn test_burn_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -3353,41 +3343,41 @@ mod tests { #[test] fn test_burn() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); - let mismatch_key = pubkey_rand(); + let mismatch_key = Pubkey::new_unique(); let mut mismatch_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut rent_sysvar = rent_sysvar(); // create new mint @@ -3611,34 +3601,34 @@ mod tests { #[test] fn test_multisig() { - let program_id = pubkey_rand(); - let mint_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let multisig_key = pubkey_rand(); + let multisig_key = Pubkey::new_unique(); let mut multisig_account = SolanaAccount::new(42, Multisig::get_packed_len(), &program_id); - let multisig_delegate_key = pubkey_rand(); + let multisig_delegate_key = Pubkey::new_unique(); let mut multisig_delegate_account = SolanaAccount::new( multisig_minimum_balance(), Multisig::get_packed_len(), &program_id, ); - let signer_keys = vec![pubkey_rand(); MAX_SIGNERS]; - let signer_key_refs: Vec<&Pubkey> = signer_keys.iter().map(|key| key).collect(); + let signer_keys = vec![Pubkey::new_unique(); MAX_SIGNERS]; + let signer_key_refs: Vec<&Pubkey> = signer_keys.iter().collect(); let mut signer_accounts = vec![SolanaAccount::new(0, 0, &program_id); MAX_SIGNERS]; let mut rent_sysvar = rent_sysvar(); @@ -3903,13 +3893,13 @@ mod tests { .unwrap(); // freeze account - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut mint2_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); do_process_instruction( @@ -4015,11 +4005,11 @@ mod tests { #[test] fn test_validate_owner() { - let program_id = pubkey_rand(); - let owner_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let owner_key = Pubkey::new_unique(); let mut signer_keys = [Pubkey::default(); MAX_SIGNERS]; for signer_key in signer_keys.iter_mut().take(MAX_SIGNERS) { - *signer_key = pubkey_rand(); + *signer_key = Pubkey::new_unique(); } let mut signer_lamports = 0; let mut signer_data = vec![]; @@ -4175,23 +4165,23 @@ mod tests { #[test] fn test_close_account_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account2_info: AccountInfo = (&account2_key, true, &mut account2_account).into(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, false, &mut mint_account).into(); @@ -4261,31 +4251,31 @@ mod tests { #[test] fn test_close_account() { - let program_id = pubkey_rand(); - let mint_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance() + 42, Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); let mut rent_sysvar = rent_sysvar(); @@ -4402,13 +4392,13 @@ mod tests { assert_eq!(account.amount, 0); // fund and initialize new non-native account to test close authority - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), @@ -4490,24 +4480,24 @@ mod tests { #[test] fn test_native_token() { - let program_id = pubkey_rand(); + let program_id = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance() + 40, Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new(account_minimum_balance(), 0, &program_id); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let mut rent_sysvar = rent_sysvar(); @@ -4571,7 +4561,7 @@ mod tests { ); // burn unsupported - let bogus_mint_key = pubkey_rand(); + let bogus_mint_key = Pubkey::new_unique(); let mut bogus_mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); do_process_instruction( @@ -4667,26 +4657,26 @@ mod tests { #[test] fn test_overflow() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_owner_key = pubkey_rand(); + let mint_owner_key = Pubkey::new_unique(); let mut mint_owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -4844,22 +4834,22 @@ mod tests { #[test] fn test_frozen() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -4956,7 +4946,7 @@ mod tests { let mut account = Account::unpack_unchecked(&account_account.data).unwrap(); account.state = AccountState::Frozen; Account::pack(account, &mut account_account.data).unwrap(); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); assert_eq!( Err(TokenError::AccountFrozen.into()), @@ -4992,7 +4982,7 @@ mod tests { ); // no set authority if account is frozen - let new_owner_key = pubkey_rand(); + let new_owner_key = Pubkey::new_unique(); assert_eq!( Err(TokenError::AccountFrozen.into()), do_process_instruction( @@ -5030,16 +5020,16 @@ mod tests { #[test] fn test_freeze_thaw_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -5094,20 +5084,20 @@ mod tests { #[test] fn test_freeze_account() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account_owner_key = pubkey_rand(); + let account_owner_key = Pubkey::new_unique(); let mut account_owner_account = SolanaAccount::default(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); diff --git a/token/program-v3/src/state.rs b/token/program-v3/src/state.rs index 3622471e..c35f3428 100644 --- a/token/program-v3/src/state.rs +++ b/token/program-v3/src/state.rs @@ -3,7 +3,7 @@ use crate::instruction::MAX_SIGNERS; use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; use num_enum::TryFromPrimitive; -use solana_sdk::{ +use solana_program::{ program_error::ProgramError, program_option::COption, program_pack::{IsInitialized, Pack, Sealed}, diff --git a/token/program/Cargo.toml b/token/program/Cargo.toml index d22324ec..6e20a1aa 100644 --- a/token/program/Cargo.toml +++ b/token/program/Cargo.toml @@ -1,6 +1,3 @@ - -# Note: This crate must be built using do.sh - [package] name = "spl-token" version = "2.0.8" @@ -12,21 +9,18 @@ edition = "2018" exclude = ["js/**"] [features] -no-entrypoint = [] -program = ["solana-sdk/program"] -default = ["solana-sdk/default"] +exclude_entrypoint = [] [dependencies] num-derive = "0.3" num-traits = "0.2" remove_dir_all = "=0.5.0" -solana-sdk = { version = "1.3.17", default-features = false, optional = true } +solana-program = "1.4.3" thiserror = "1.0" arrayref = "0.3.6" num_enum = "0.5.1" [dev-dependencies] -rand = { version = "0.7.0"} [lib] crate-type = ["cdylib", "lib"] diff --git a/token/program/src/entrypoint.rs b/token/program/src/entrypoint.rs index b5594ca8..b2555132 100644 --- a/token/program/src/entrypoint.rs +++ b/token/program/src/entrypoint.rs @@ -1,10 +1,7 @@ //! Program entrypoint -#![cfg(feature = "program")] -#![cfg(not(feature = "no-entrypoint"))] - use crate::{error::TokenError, processor::Processor}; -use solana_sdk::{ +use solana_program::{ account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, program_error::PrintProgramError, pubkey::Pubkey, }; diff --git a/token/program/src/error.rs b/token/program/src/error.rs index 32cd9d20..8305eaad 100644 --- a/token/program/src/error.rs +++ b/token/program/src/error.rs @@ -1,7 +1,7 @@ //! Error types use num_derive::FromPrimitive; -use solana_sdk::{decode_error::DecodeError, program_error::ProgramError}; +use solana_program::{decode_error::DecodeError, program_error::ProgramError}; use thiserror::Error; /// Errors that may be returned by the Token program. diff --git a/token/program/src/instruction.rs b/token/program/src/instruction.rs index de75b736..1d266433 100644 --- a/token/program/src/instruction.rs +++ b/token/program/src/instruction.rs @@ -1,7 +1,7 @@ //! Instruction types use crate::error::TokenError; -use solana_sdk::{ +use solana_program::{ instruction::{AccountMeta, Instruction}, program_error::ProgramError, program_option::COption, diff --git a/token/program/src/lib.rs b/token/program/src/lib.rs index 6e7108fe..fc9707df 100644 --- a/token/program/src/lib.rs +++ b/token/program/src/lib.rs @@ -3,16 +3,17 @@ //! An ERC20-like Token program for the Solana blockchain -pub mod entrypoint; pub mod error; pub mod instruction; pub mod native_mint; pub mod processor; pub mod state; -// Export current solana-sdk types for downstream users who may also be building with a different -// solana-sdk version -pub use solana_sdk; +#[cfg(not(feature = "exclude_entrypoint"))] +mod entrypoint; + +// Export current sdk types for downstream users building with a different sdk version +pub use solana_program; /// Convert the UI representation of a token amount (using the decimals field defined in its mint) /// to the raw amount @@ -25,4 +26,4 @@ pub fn amount_to_ui_amount(amount: u64, decimals: u8) -> f64 { amount as f64 / 10_usize.pow(decimals as u32) as f64 } -solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); +solana_program::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); diff --git a/token/program/src/native_mint.rs b/token/program/src/native_mint.rs index 740b8abb..0502f9f7 100644 --- a/token/program/src/native_mint.rs +++ b/token/program/src/native_mint.rs @@ -4,12 +4,12 @@ pub const DECIMALS: u8 = 9; // The Mint for native SOL Token accounts -solana_sdk::declare_id!("So11111111111111111111111111111111111111112"); +solana_program::declare_id!("So11111111111111111111111111111111111111112"); #[cfg(test)] mod tests { use super::*; - use solana_sdk::native_token::*; + use solana_program::native_token::*; #[test] fn test_decimals() { diff --git a/token/program/src/processor.rs b/token/program/src/processor.rs index ac83ca82..c9b5e10c 100644 --- a/token/program/src/processor.rs +++ b/token/program/src/processor.rs @@ -1,6 +1,6 @@ //! Program state processor -#![cfg(feature = "program")] +//#![cfg(feature = "program")] use crate::{ error::TokenError, @@ -8,7 +8,7 @@ use crate::{ state::{Account, AccountState, Mint, Multisig}, }; use num_traits::FromPrimitive; -use solana_sdk::{ +use solana_program::{ account_info::{next_account_info, AccountInfo}, decode_error::DecodeError, entrypoint::ProgramResult, @@ -780,23 +780,15 @@ impl PrintProgramError for TokenError { } } -// Pull in syscall stubs when building for non-BPF targets -#[cfg(not(target_arch = "bpf"))] -solana_sdk::program_stubs!(); - #[cfg(test)] mod tests { use super::*; use crate::instruction::*; - use solana_sdk::{ + use solana_program::{ account::Account as SolanaAccount, account_info::create_is_signer_account_infos, clock::Epoch, instruction::Instruction, sysvar::rent, }; - fn pubkey_rand() -> Pubkey { - Pubkey::new(&rand::random::<[u8; 32]>()) - } - fn do_process_instruction( instruction: Instruction, accounts: Vec<&mut SolanaAccount>, @@ -968,11 +960,11 @@ mod tests { #[test] fn test_initialize_mint() { - let program_id = pubkey_rand(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(42, Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut mint2_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -1016,12 +1008,12 @@ mod tests { #[test] fn test_initialize_mint_account() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new(42, Account::get_packed_len(), &program_id); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -1092,46 +1084,46 @@ mod tests { #[test] fn test_transfer_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let mut account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let mut account2_info: AccountInfo = (&account2_key, false, &mut account2_account).into(); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account3_info: AccountInfo = (&account3_key, false, &mut account3_account).into(); - let account4_key = pubkey_rand(); + let account4_key = Pubkey::new_unique(); let mut account4_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account4_info: AccountInfo = (&account4_key, true, &mut account4_account).into(); - let multisig_key = pubkey_rand(); + let multisig_key = Pubkey::new_unique(); let mut multisig_account = SolanaAccount::new( multisig_minimum_balance(), Multisig::get_packed_len(), &program_id, ); let multisig_info: AccountInfo = (&multisig_key, true, &mut multisig_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, false, &mut mint_account).into(); @@ -1399,41 +1391,41 @@ mod tests { #[test] fn test_transfer() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); - let mismatch_key = pubkey_rand(); + let mismatch_key = Pubkey::new_unique(); let mut mismatch_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut rent_sysvar = rent_sysvar(); // create mint @@ -1729,7 +1721,7 @@ mod tests { // This is probably wrong but transactions in the wild have been observed to do this so // this behavior is now part of the token ABI { - let system_account_key = pubkey_rand(); + let system_account_key = Pubkey::new_unique(); let mut system_account = SolanaAccount::new(1, 0, &Pubkey::default()); let instruction = transfer( @@ -1898,16 +1890,16 @@ mod tests { #[test] fn test_mintable_token_with_zero_supply() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -1949,7 +1941,7 @@ mod tests { vec![&mut mint_account, &mut account_account, &mut owner_account], ) .unwrap(); - let _ = Mint::unpack(&mut mint_account.data).unwrap(); + let _ = Mint::unpack(&mint_account.data).unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); assert_eq!(account.amount, 42); @@ -1971,7 +1963,7 @@ mod tests { ) ); - let _ = Mint::unpack(&mut mint_account.data).unwrap(); + let _ = Mint::unpack(&mint_account.data).unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); assert_eq!(account.amount, 42); @@ -1990,46 +1982,46 @@ mod tests { vec![&mut mint_account, &mut account_account, &mut owner_account], ) .unwrap(); - let _ = Mint::unpack(&mut mint_account.data).unwrap(); + let _ = Mint::unpack(&mint_account.data).unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); assert_eq!(account.amount, 84); } #[test] fn test_approve_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account2_info: AccountInfo = (&account2_key, false, &mut account2_account).into(); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account3_info: AccountInfo = (&account3_key, true, &mut account3_account).into(); - let multisig_key = pubkey_rand(); + let multisig_key = Pubkey::new_unique(); let mut multisig_account = SolanaAccount::new( multisig_minimum_balance(), Multisig::get_packed_len(), &program_id, ); let multisig_info: AccountInfo = (&multisig_key, true, &mut multisig_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, false, &mut mint_account).into(); @@ -2208,26 +2200,26 @@ mod tests { #[test] fn test_approve() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -2413,16 +2405,16 @@ mod tests { #[test] fn test_set_authority_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -2516,28 +2508,28 @@ mod tests { #[test] fn test_set_authority() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let owner3_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner3_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut mint2_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -2855,18 +2847,18 @@ mod tests { #[test] fn test_mint_to_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -2951,40 +2943,40 @@ mod tests { #[test] fn test_mint_to() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let mismatch_key = pubkey_rand(); + let mismatch_key = Pubkey::new_unique(); let mut mismatch_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); - let uninitialized_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); + let uninitialized_key = Pubkey::new_unique(); let mut uninitialized_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), @@ -3154,18 +3146,18 @@ mod tests { #[test] fn test_burn_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let owner_info: AccountInfo = (&owner_key, true, &mut owner_account).into(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -3354,41 +3346,41 @@ mod tests { #[test] fn test_burn() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); - let mismatch_key = pubkey_rand(); + let mismatch_key = Pubkey::new_unique(); let mut mismatch_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut rent_sysvar = rent_sysvar(); // create new mint @@ -3619,34 +3611,34 @@ mod tests { #[test] fn test_multisig() { - let program_id = pubkey_rand(); - let mint_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let multisig_key = pubkey_rand(); + let multisig_key = Pubkey::new_unique(); let mut multisig_account = SolanaAccount::new(42, Multisig::get_packed_len(), &program_id); - let multisig_delegate_key = pubkey_rand(); + let multisig_delegate_key = Pubkey::new_unique(); let mut multisig_delegate_account = SolanaAccount::new( multisig_minimum_balance(), Multisig::get_packed_len(), &program_id, ); - let signer_keys = vec![pubkey_rand(); MAX_SIGNERS]; - let signer_key_refs: Vec<&Pubkey> = signer_keys.iter().map(|key| key).collect(); + let signer_keys = vec![Pubkey::new_unique(); MAX_SIGNERS]; + let signer_key_refs: Vec<&Pubkey> = signer_keys.iter().collect(); let mut signer_accounts = vec![SolanaAccount::new(0, 0, &program_id); MAX_SIGNERS]; let mut rent_sysvar = rent_sysvar(); @@ -3911,13 +3903,13 @@ mod tests { .unwrap(); // freeze account - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let mint2_key = pubkey_rand(); + let mint2_key = Pubkey::new_unique(); let mut mint2_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); do_process_instruction( @@ -4023,11 +4015,11 @@ mod tests { #[test] fn test_validate_owner() { - let program_id = pubkey_rand(); - let owner_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let owner_key = Pubkey::new_unique(); let mut signer_keys = [Pubkey::default(); MAX_SIGNERS]; for signer_key in signer_keys.iter_mut().take(MAX_SIGNERS) { - *signer_key = pubkey_rand(); + *signer_key = Pubkey::new_unique(); } let mut signer_lamports = 0; let mut signer_data = vec![]; @@ -4183,23 +4175,23 @@ mod tests { #[test] fn test_close_account_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account2_info: AccountInfo = (&account2_key, true, &mut account2_account).into(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, false, &mut mint_account).into(); @@ -4269,31 +4261,31 @@ mod tests { #[test] fn test_close_account() { - let program_id = pubkey_rand(); - let mint_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance() + 42, Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); let mut rent_sysvar = rent_sysvar(); @@ -4410,13 +4402,13 @@ mod tests { assert_eq!(account.amount, 0); // fund and initialize new non-native account to test close authority - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), @@ -4498,24 +4490,24 @@ mod tests { #[test] fn test_native_token() { - let program_id = pubkey_rand(); + let program_id = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); - let account_key = pubkey_rand(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance() + 40, Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account3_key = pubkey_rand(); + let account3_key = Pubkey::new_unique(); let mut account3_account = SolanaAccount::new(account_minimum_balance(), 0, &program_id); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); let mut rent_sysvar = rent_sysvar(); @@ -4579,7 +4571,7 @@ mod tests { ); // burn unsupported - let bogus_mint_key = pubkey_rand(); + let bogus_mint_key = Pubkey::new_unique(); let mut bogus_mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); do_process_instruction( @@ -4675,26 +4667,26 @@ mod tests { #[test] fn test_overflow() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_owner_key = pubkey_rand(); + let mint_owner_key = Pubkey::new_unique(); let mut mint_owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -4852,22 +4844,22 @@ mod tests { #[test] fn test_frozen() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account2_key = pubkey_rand(); + let account2_key = Pubkey::new_unique(); let mut account2_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); @@ -4964,7 +4956,7 @@ mod tests { let mut account = Account::unpack_unchecked(&account_account.data).unwrap(); account.state = AccountState::Frozen; Account::pack(account, &mut account_account.data).unwrap(); - let delegate_key = pubkey_rand(); + let delegate_key = Pubkey::new_unique(); let mut delegate_account = SolanaAccount::default(); assert_eq!( Err(TokenError::AccountFrozen.into()), @@ -5000,7 +4992,7 @@ mod tests { ); // no set authority if account is frozen - let new_owner_key = pubkey_rand(); + let new_owner_key = Pubkey::new_unique(); assert_eq!( Err(TokenError::AccountFrozen.into()), do_process_instruction( @@ -5038,16 +5030,16 @@ mod tests { #[test] fn test_freeze_thaw_dups() { - let program_id = pubkey_rand(); - let account1_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account1_key = Pubkey::new_unique(); let mut account1_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); let account1_info: AccountInfo = (&account1_key, true, &mut account1_account).into(); - let owner_key = pubkey_rand(); - let mint_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mint_info: AccountInfo = (&mint_key, true, &mut mint_account).into(); @@ -5102,20 +5094,20 @@ mod tests { #[test] fn test_freeze_account() { - let program_id = pubkey_rand(); - let account_key = pubkey_rand(); + let program_id = Pubkey::new_unique(); + let account_key = Pubkey::new_unique(); let mut account_account = SolanaAccount::new( account_minimum_balance(), Account::get_packed_len(), &program_id, ); - let account_owner_key = pubkey_rand(); + let account_owner_key = Pubkey::new_unique(); let mut account_owner_account = SolanaAccount::default(); - let owner_key = pubkey_rand(); + let owner_key = Pubkey::new_unique(); let mut owner_account = SolanaAccount::default(); - let owner2_key = pubkey_rand(); + let owner2_key = Pubkey::new_unique(); let mut owner2_account = SolanaAccount::default(); - let mint_key = pubkey_rand(); + let mint_key = Pubkey::new_unique(); let mut mint_account = SolanaAccount::new(mint_minimum_balance(), Mint::get_packed_len(), &program_id); let mut rent_sysvar = rent_sysvar(); diff --git a/token/program/src/state.rs b/token/program/src/state.rs index 3622471e..c35f3428 100644 --- a/token/program/src/state.rs +++ b/token/program/src/state.rs @@ -3,7 +3,7 @@ use crate::instruction::MAX_SIGNERS; use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs}; use num_enum::TryFromPrimitive; -use solana_sdk::{ +use solana_program::{ program_error::ProgramError, program_option::COption, program_pack::{IsInitialized, Pack, Sealed}, diff --git a/update-solana-dependencies.sh b/update-solana-dependencies.sh new file mode 100755 index 00000000..6a892281 --- /dev/null +++ b/update-solana-dependencies.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# Updates the solana version in all the SPL crates +# + +solana_ver=$1 +if [[ -z $solana_ver ]]; then + echo "Usage: $0 " + exit 1 +fi + +cd "$(dirname "$0")" + +declare tomls=() +while IFS='' read -r line; do tomls+=("$line"); done < <(find . -name Cargo.toml) + +crates=( + solana-account-decoder + solana-banks-client + solana-banks-server + solana-bpf-loader-program + solana-clap-utils + solana-cli-config + solana-cli-output + solana-client + solana-core + solana-logger + solana-program + solana-runtime + solana-sdk +) + +set -x +for crate in "${crates[@]}"; do + sed -i -e "s#\(${crate} = \"\).*\(\"\)#\1$solana_ver\2#g" "${tomls[@]}" +done + +#sed -i -e "s#\(solana-sdk = { version = \"\).*\(\"\)#\1$solana_ver\2#g" "${tomls[@]}" +#sed -i -e "s#\(solana-client = \"\).*\(\"\)#\1$solana_ver\2#g" "${tomls[@]}" + + diff --git a/utils/test-client/Cargo.toml b/utils/test-client/Cargo.toml index edf6bbc9..a7294f40 100644 --- a/utils/test-client/Cargo.toml +++ b/utils/test-client/Cargo.toml @@ -8,8 +8,8 @@ edition = "2018" # Used to ensure that SPL programs are buildable by external clients [dependencies] -solana-sdk = "1.3.11" -spl-memo = { path = "../../memo/program" } -spl-token = { path = "../../token/program" } -spl-token-v3 = { path = "../../token/program-v3" } -spl-token-swap = { path = "../../token-swap/program" } +solana-sdk = "1.4.3" +spl-memo = { path = "../../memo/program", features = [ "exclude_entrypoint" ] } +spl-token = { path = "../../token/program", features = [ "exclude_entrypoint" ] } +spl-token-swap = { path = "../../token-swap/program", features = [ "exclude_entrypoint" ] } +spl-token-v3 = { path = "../../token/program-v3", features = [ "exclude_entrypoint" ] } diff --git a/utils/test-client/src/main b/utils/test-client/src/main deleted file mode 100644 index e69de29b..00000000