Use procedural macro to generate static public keys (bp #7219) (#7241)

automerge
This commit is contained in:
Justin Starry
2019-12-03 22:07:19 -05:00
committed by Grimes
parent 57dce86d5e
commit 35ae76532a
13 changed files with 298 additions and 167 deletions

12
Cargo.lock generated
View File

@ -3862,7 +3862,6 @@ dependencies = [
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3877,6 +3876,7 @@ dependencies = [
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-crate-features 0.21.1",
"solana-logger 0.21.1",
"solana-sdk-macro 0.21.1",
"tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -3895,6 +3895,16 @@ dependencies = [
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-sdk-macro"
version = "0.21.1"
dependencies = [
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-stake-program"
version = "0.21.1"

203
programs/bpf/Cargo.lock generated
View File

@ -245,12 +245,12 @@ dependencies = [
[[package]]
name = "chrono"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -822,7 +822,7 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1117,7 +1117,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1585,156 +1585,157 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "solana-bpf-loader-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-sdk 0.21.1",
"solana_rbpf 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-bpf-programs"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"elf 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-bpf-loader-program 0.21.0",
"solana-logger 0.21.0",
"solana-runtime 0.21.0",
"solana-sdk 0.21.0",
"solana-bpf-loader-program 0.21.1",
"solana-logger 0.21.1",
"solana-runtime 0.21.1",
"solana-sdk 0.21.1",
"solana_rbpf 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-bpf-rust-128bit"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-bpf-rust-128bit-dep 0.21.0",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-bpf-rust-128bit-dep 0.21.1",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-128bit-dep"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-alloc"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-dep-crate"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-external-spend"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-iter"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-many-args"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-bpf-rust-many-args-dep 0.21.0",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-bpf-rust-many-args-dep 0.21.1",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-many-args-dep"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-noop"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-panic"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-param-passing"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-bpf-rust-param-passing-dep 0.21.0",
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-bpf-rust-param-passing-dep 0.21.1",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-param-passing-dep"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-bpf-rust-sysval"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk-bpf-test 0.21.0",
"solana-sdk 0.21.1",
"solana-sdk-bpf-test 0.21.1",
]
[[package]]
name = "solana-config-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-crate-features"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1757,7 +1758,7 @@ dependencies = [
[[package]]
name = "solana-logger"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1766,26 +1767,26 @@ dependencies = [
[[package]]
name = "solana-measure"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"solana-sdk 0.21.0",
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-metrics"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-sdk 0.21.0",
"solana-sdk 0.21.1",
"sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-rayon-threadlimit"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1793,14 +1794,14 @@ dependencies = [
[[package]]
name = "solana-runtime"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bv 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1811,22 +1812,22 @@ dependencies = [
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-bpf-loader-program 0.21.0",
"solana-logger 0.21.0",
"solana-measure 0.21.0",
"solana-metrics 0.21.0",
"solana-rayon-threadlimit 0.21.0",
"solana-sdk 0.21.0",
"solana-stake-program 0.21.0",
"solana-storage-program 0.21.0",
"solana-vote-program 0.21.0",
"solana-bpf-loader-program 0.21.1",
"solana-logger 0.21.1",
"solana-measure 0.21.1",
"solana-metrics 0.21.1",
"solana-rayon-threadlimit 0.21.1",
"solana-sdk 0.21.1",
"solana-stake-program 0.21.1",
"solana-storage-program 0.21.1",
"solana-vote-program 0.21.1",
"sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-sdk"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1836,8 +1837,7 @@ dependencies = [
"generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1850,17 +1850,28 @@ dependencies = [
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-crate-features 0.21.0",
"solana-logger 0.21.0",
"solana-crate-features 0.21.1",
"solana-logger 0.21.1",
"solana-sdk-macro 0.21.1",
]
[[package]]
name = "solana-sdk-bpf-test"
version = "0.21.0"
version = "0.21.1"
[[package]]
name = "solana-sdk-macro"
version = "0.21.1"
dependencies = [
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "solana-stake-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1869,16 +1880,16 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-config-program 0.21.0",
"solana-logger 0.21.0",
"solana-metrics 0.21.0",
"solana-sdk 0.21.0",
"solana-vote-program 0.21.0",
"solana-config-program 0.21.1",
"solana-logger 0.21.1",
"solana-metrics 0.21.1",
"solana-sdk 0.21.1",
"solana-vote-program 0.21.1",
]
[[package]]
name = "solana-storage-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1887,13 +1898,13 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-sdk 0.21.1",
]
[[package]]
name = "solana-vote-program"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1901,9 +1912,9 @@ dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 0.21.0",
"solana-metrics 0.21.0",
"solana-sdk 0.21.0",
"solana-logger 0.21.1",
"solana-metrics 0.21.1",
"solana-sdk 0.21.1",
]
[[package]]
@ -2601,7 +2612,7 @@ dependencies = [
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c"
"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68"
"checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
@ -2662,7 +2673,7 @@ dependencies = [
"checksum indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a61202fbe46c4a951e9404a720a0180bcf3212c750d735cb5c4ba4dc551299f3"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d"
"checksum itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "87fa75c9dea7b07be3138c49abbb83fd4bea199b5cdc76f9804458edc5da0d6e"
"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum jobserver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b1d42ef453b30b7387e113da1c83ab1605d90c5b4e0eb8e96d016ed3b8c160"
"checksum js-sys 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "1efc4f2a556c58e79c5500912e221dd826bec64ff4aabd8ce71ccef6da02d7d4"

View File

@ -6,10 +6,11 @@ use solana_sdk::{
clock::{get_segment_from_slot, DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT},
entrypoint,
entrypoint::SUCCESS,
info,
pubkey::Pubkey,
rent,
sysvar::{
clock::Clock, fees::Fees, rent::Rent, rewards::Rewards, slot_hashes::SlotHashes,
self, clock::Clock, fees::Fees, rent::Rent, rewards::Rewards, slot_hashes::SlotHashes,
stake_history::StakeHistory, Sysvar,
},
};
@ -17,6 +18,8 @@ use solana_sdk::{
entrypoint!(process_instruction);
fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], _data: &[u8]) -> u32 {
// Clock
info!("Clock identifier:");
sysvar::clock::id().log();
let clock = Clock::from_account_info(&accounts[2]).expect("clock");
assert_eq!(clock.slot, DEFAULT_SLOTS_PER_EPOCH + 1);
assert_eq!(
@ -25,18 +28,26 @@ fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], _data
);
// Fees
info!("Fees identifier:");
sysvar::fees::id().log();
let fees = Fees::from_account_info(&accounts[3]).expect("fees");
let burn = fees.fee_calculator.burn(42);
assert_eq!(burn, (21, 21));
// Rewards
info!("Rewards identifier:");
sysvar::rewards::id().log();
let _rewards = Rewards::from_account_info(&accounts[4]).expect("rewards");
// Slot Hashes
info!("SlotHashes identifier:");
sysvar::slot_hashes::id().log();
let slot_hashes = SlotHashes::from_account_info(&accounts[5]).expect("slot_hashes");
assert!(slot_hashes.len() >= 1);
// Stake History
info!("StakeHistory identifier:");
sysvar::stake_history::id().log();
let stake_history = StakeHistory::from_account_info(&accounts[6]).expect("stake_history");
assert!(stake_history.len() >= 1);

View File

@ -7,7 +7,6 @@ use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use log::*;
use solana_rbpf::{memory_region::MemoryRegion, EbpfVm};
use solana_sdk::account::KeyedAccount;
use solana_sdk::bpf_loader;
use solana_sdk::instruction::InstructionError;
use solana_sdk::instruction_processor_utils::{limited_deserialize, next_keyed_account};
use solana_sdk::loader_instruction::LoaderInstruction;
@ -19,7 +18,7 @@ use std::io::Error;
use std::mem;
solana_sdk::declare_program!(
bpf_loader::BS58_STRING,
solana_sdk::bpf_loader::ID,
solana_bpf_loader_program,
process_instruction
);

View File

@ -4,10 +4,9 @@ pub mod error_mappers;
pub mod processor;
use crate::processor::process_instruction;
use solana_sdk::move_loader;
solana_sdk::declare_program!(
move_loader::BS58_STRING,
solana_sdk::move_loader::ID,
solana_move_loader_program,
process_instruction
);

View File

@ -33,7 +33,6 @@ generic-array = { version = "0.13.2", default-features = false, features = ["ser
hex = "0.4.0"
hmac = "0.7.0"
itertools = { version = "0.8.2" }
lazy_static = "1.4.0"
log = { version = "0.4.8" }
memmap = { version = "0.6.2", optional = true }
num-derive = { version = "0.3" }
@ -47,8 +46,9 @@ serde_derive = "1.0.102"
serde_json = { version = "1.0.41", optional = true }
sha2 = "0.8.0"
ed25519-dalek = { version = "1.0.0-pre.1", optional = true }
solana-logger = { path = "../logger", version = "0.21.1", optional = true }
solana-crate-features = { path = "../crate-features", version = "0.21.1", optional = true }
solana-logger = { path = "../logger", version = "0.21.1", optional = true }
solana-sdk-macro = { path = "macro" }
[dev-dependencies]
tiny-bip39 = "0.6.2"

18
sdk/macro/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "solana-sdk-macro"
version = "0.21.1"
description = "Solana SDK Macro"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
homepage = "https://solana.com/"
license = "Apache-2.0"
edition = "2018"
[lib]
proc-macro = true
[dependencies]
bs58 = "0.3.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full", "extra-traits"] }

73
sdk/macro/src/lib.rs Normal file
View File

@ -0,0 +1,73 @@
//! Convenience macro to declare a static public key and functions to interact with it
//!
//! Input: a single literal base58 string representation of a program's id
extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::{quote, ToTokens};
use std::convert::TryFrom;
use syn::{
parse::{Parse, ParseStream, Result},
parse_macro_input, Expr, LitByte, LitStr,
};
struct Id(proc_macro2::TokenStream);
impl Parse for Id {
fn parse(input: ParseStream) -> Result<Self> {
let token_stream = if input.peek(syn::LitStr) {
let id_literal: LitStr = input.parse()?;
let id_vec = bs58::decode(id_literal.value())
.into_vec()
.map_err(|_| syn::Error::new_spanned(&id_literal, "failed to decode base58 id"))?;
let id_array = <[u8; 32]>::try_from(<&[u8]>::clone(&&id_vec[..]))
.map_err(|_| syn::Error::new_spanned(&id_literal, "id is not 32 bytes long"))?;
let bytes = id_array.iter().map(|b| LitByte::new(*b, Span::call_site()));
quote! {
::solana_sdk::pubkey::Pubkey::new_from_array(
[#(#bytes,)*]
)
}
} else {
let expr: Expr = input.parse()?;
quote! { #expr }
};
if !input.is_empty() {
let stream: proc_macro2::TokenStream = input.parse()?;
return Err(syn::Error::new_spanned(stream, "unexpected token"));
}
Ok(Id(token_stream))
}
}
impl ToTokens for Id {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let id = &self.0;
tokens.extend(quote! {
pub static ID: ::solana_sdk::pubkey::Pubkey = #id;
pub fn check_id(id: &::solana_sdk::pubkey::Pubkey) -> bool {
id == &ID
}
pub fn id() -> ::solana_sdk::pubkey::Pubkey {
ID
}
#[cfg(test)]
#[test]
fn test_id() {
assert!(check_id(&id()));
}
});
}
}
#[proc_macro]
pub fn declare_id(input: TokenStream) -> TokenStream {
let id = parse_macro_input!(input as Id);
TokenStream::from(quote! {#id})
}

View File

@ -1,2 +1 @@
pub const BS58_STRING: &str = "BPFLoader1111111111111111111111111111111111";
crate::declare_id!(BS58_STRING);
crate::declare_id!("BPFLoader1111111111111111111111111111111111");

View File

@ -37,6 +37,10 @@ macro_rules! solana_entrypoint(
/// # Examples
///
/// ```
/// use std::str::FromStr;
/// # // wrapper is used so that the macro invocation occurs in the item position
/// # // rather than in the statement position which isn't allowed.
/// # mod item_wrapper {
/// use solana_sdk::account::KeyedAccount;
/// use solana_sdk::instruction::InstructionError;
/// use solana_sdk::pubkey::Pubkey;
@ -51,11 +55,46 @@ macro_rules! solana_entrypoint(
/// Ok(())
/// }
///
/// solana_sdk::declare_program!(
/// "My!!!11111111111111111111111111111111111111",
/// declare_program!(
/// "My11111111111111111111111111111111111111111",
/// solana_my_program,
/// my_process_instruction
/// );
///
/// # }
/// # use solana_sdk::pubkey::Pubkey;
/// # use item_wrapper::id;
/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
/// assert_eq!(id(), my_id);
/// ```
/// ```
/// use std::str::FromStr;
/// # // wrapper is used so that the macro invocation occurs in the item position
/// # // rather than in the statement position which isn't allowed.
/// # mod item_wrapper {
/// use solana_sdk::account::KeyedAccount;
/// use solana_sdk::instruction::InstructionError;
/// use solana_sdk::pubkey::Pubkey;
/// use solana_sdk::declare_program;
///
/// fn my_process_instruction(
/// program_id: &Pubkey,
/// keyed_accounts: &mut [KeyedAccount],
/// data: &[u8],
/// ) -> Result<(), InstructionError> {
/// // Process an instruction
/// Ok(())
/// }
///
/// declare_program!(
/// solana_sdk::system_program::ID,
/// solana_my_program,
/// my_process_instruction
/// );
/// # }
///
/// # use item_wrapper::id;
/// assert_eq!(id(), solana_sdk::system_program::ID);
/// ```
#[macro_export]
macro_rules! declare_program(

View File

@ -1,3 +1,6 @@
// Allows macro expansion of `use ::solana_sdk::*` to work within this crate
extern crate self as solana_sdk;
pub mod account;
pub mod account_utils;
pub mod bpf_loader;
@ -24,6 +27,29 @@ pub mod system_program;
pub mod sysvar;
pub mod timing;
/// Convenience macro to declare a static public key and functions to interact with it
///
/// Input: a single literal base58 string representation of a program's id
///
/// # Example
///
/// ```
/// # // wrapper is used so that the macro invocation occurs in the item position
/// # // rather than in the statement position which isn't allowed.
/// use std::str::FromStr;
/// use solana_sdk::{declare_id, pubkey::Pubkey};
///
/// # mod item_wrapper {
/// # use solana_sdk::declare_id;
/// declare_id!("My11111111111111111111111111111111111111111");
/// # }
/// # use item_wrapper::id;
///
/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
/// assert_eq!(id(), my_id);
/// ```
pub use solana_sdk_macro::declare_id;
// On-chain program specific modules
pub mod account_info;
pub mod entrypoint;
@ -52,5 +78,4 @@ pub mod transport;
#[macro_use]
extern crate serde_derive;
pub extern crate bs58;
pub extern crate lazy_static;
extern crate log as logger;

View File

@ -1,5 +1,4 @@
pub const BS58_STRING: &str = "MoveLdr111111111111111111111111111111111111";
crate::declare_id!(BS58_STRING);
crate::declare_id!("MoveLdr111111111111111111111111111111111111");
pub fn solana_move_loader_program() -> (String, crate::pubkey::Pubkey) {
("solana_move_loader_program".to_string(), id())

View File

@ -47,6 +47,10 @@ impl Pubkey {
)
}
pub const fn new_from_array(pubkey_array: [u8; 32]) -> Self {
Self(pubkey_array)
}
#[cfg(not(feature = "program"))]
pub fn new_rand() -> Self {
Self::new(&rand::random::<[u8; 32]>())
@ -104,62 +108,6 @@ pub fn read_pubkey_file(infile: &str) -> Result<Pubkey, Box<dyn error::Error>> {
Ok(Pubkey::from_str(&printable)?)
}
/// Convenience macro to declare a static Pubkey and functions to interact with it
///
/// bs58_string: bs58 string representation the program's id
///
/// # Examples
///
/// ```
/// solana_sdk::declare_id!("My!!!11111111111111111111111111111111111111");
/// ```
#[macro_export]
macro_rules!
declare_id(
($bs58_string:expr) => (
use std::str::FromStr;
$crate::lazy_static::lazy_static! {
static ref _PUBKEY: $crate::pubkey::Pubkey = {
match $crate::pubkey::Pubkey::from_str(&$bs58_string) {
Ok(pubkey) => pubkey,
Err(_) => {
let pubkey_vec = $crate::bs58::decode(&$bs58_string)
.into_vec()
.map_err(|e| panic!("Error: {}, {}", $bs58_string, e))
.unwrap();
let expected_len = std::mem::size_of::<$crate::pubkey::Pubkey>();
let len = pubkey_vec.len();
if len != expected_len {
panic!(
"Error: {}, decoded length {}, expected {}",
$bs58_string, len, expected_len);
} else {
panic!(
"Error: {}, not a valid string, cannot determine reason",
$bs58_string);
}
}
}
};
}
pub fn check_id(id: &$crate::pubkey::Pubkey) -> bool {
*id == *_PUBKEY
}
pub fn id() -> $crate::pubkey::Pubkey {
*_PUBKEY
}
#[cfg(test)]
#[test]
fn test_id() {
assert!(check_id(&id()));
}
)
);
#[cfg(test)]
mod tests {
use super::*;