solana_sdk/
pubkey.rs

1#[cfg(feature = "full")]
2pub use solana_pubkey::new_rand;
3#[cfg(target_os = "solana")]
4pub use solana_pubkey::syscalls;
5pub use solana_pubkey::{
6    bytes_are_curve_point, ParsePubkeyError, Pubkey, PubkeyError, MAX_SEEDS, MAX_SEED_LEN,
7    PUBKEY_BYTES,
8};
9
10#[deprecated(since = "2.1.0")]
11#[cfg(feature = "full")]
12pub fn write_pubkey_file(outfile: &str, pubkey: Pubkey) -> Result<(), Box<dyn std::error::Error>> {
13    use std::io::Write;
14
15    let printable = format!("{pubkey}");
16    let serialized = serde_json::to_string(&printable)?;
17
18    if let Some(outdir) = std::path::Path::new(&outfile).parent() {
19        std::fs::create_dir_all(outdir)?;
20    }
21    let mut f = std::fs::File::create(outfile)?;
22    f.write_all(&serialized.into_bytes())?;
23
24    Ok(())
25}
26
27#[deprecated(since = "2.1.0")]
28#[cfg(feature = "full")]
29pub fn read_pubkey_file(infile: &str) -> Result<Pubkey, Box<dyn std::error::Error>> {
30    let f = std::fs::File::open(infile)?;
31    let printable: String = serde_json::from_reader(f)?;
32
33    use std::str::FromStr;
34    Ok(Pubkey::from_str(&printable)?)
35}