From 0e68ed6a8d154c2532d79b80627e0a598a6b35b7 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 19 Oct 2020 11:28:42 -0700 Subject: [PATCH] Add pubkey_new_rand(), mark Pubkey::new_rand() deprecated --- sdk/src/pubkey.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index 89ccd9d557..081a56a402 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -67,6 +67,12 @@ impl FromStr for Pubkey { } } +/// New random Pubkey for tests and benchmarks. +#[cfg(feature = "everything")] +pub fn new_rand() -> Pubkey { + Pubkey::new(&rand::random::<[u8; 32]>()) +} + impl Pubkey { pub fn new(pubkey_vec: &[u8]) -> Self { Self( @@ -188,9 +194,11 @@ impl Pubkey { panic!("Unable to find a viable program address bump seed"); } - #[cfg(feature = "everything")] + #[cfg(all(feature = "everything", not(target_arch = "bpf")))] + #[deprecated(since = "1.3.9", note = "Please use 'pubkey::new_rand' instead")] pub fn new_rand() -> Self { - Self::new(&rand::random::<[u8; 32]>()) + // Consider removing Pubkey::new_rand() entirely in the v1.5 or v1.6 timeframe + new_rand() } pub fn to_bytes(self) -> [u8; 32] {