config.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. use anchor_client::Cluster;
  2. use anchor_syn::idl::Idl;
  3. use anyhow::{anyhow, Error, Result};
  4. use clap::{ArgEnum, Clap};
  5. use heck::SnakeCase;
  6. use serde::{Deserialize, Serialize};
  7. use solana_sdk::pubkey::Pubkey;
  8. use solana_sdk::signature::{Keypair, Signer};
  9. use std::collections::BTreeMap;
  10. use std::convert::TryFrom;
  11. use std::fs::{self, File};
  12. use std::io::prelude::*;
  13. use std::ops::Deref;
  14. use std::path::Path;
  15. use std::path::PathBuf;
  16. use std::str::FromStr;
  17. #[derive(Default, Debug, Clap)]
  18. pub struct ConfigOverride {
  19. /// Cluster override.
  20. #[clap(global = true, long = "provider.cluster")]
  21. pub cluster: Option<Cluster>,
  22. /// Wallet override.
  23. #[clap(global = true, long = "provider.wallet")]
  24. pub wallet: Option<WalletPath>,
  25. }
  26. pub struct WithPath<T> {
  27. inner: T,
  28. path: PathBuf,
  29. }
  30. impl<T> WithPath<T> {
  31. pub fn new(inner: T, path: PathBuf) -> Self {
  32. Self { inner, path }
  33. }
  34. pub fn path(&self) -> &PathBuf {
  35. &self.path
  36. }
  37. pub fn into_inner(self) -> T {
  38. self.inner
  39. }
  40. }
  41. impl<T> std::convert::AsRef<T> for WithPath<T> {
  42. fn as_ref(&self) -> &T {
  43. &self.inner
  44. }
  45. }
  46. #[derive(Debug, Clone, PartialEq)]
  47. pub struct Manifest(cargo_toml::Manifest);
  48. impl Manifest {
  49. pub fn from_path(p: impl AsRef<Path>) -> Result<Self> {
  50. cargo_toml::Manifest::from_path(p)
  51. .map(Manifest)
  52. .map_err(Into::into)
  53. }
  54. pub fn lib_name(&self) -> Result<String> {
  55. if self.lib.is_some() && self.lib.as_ref().unwrap().name.is_some() {
  56. Ok(self
  57. .lib
  58. .as_ref()
  59. .unwrap()
  60. .name
  61. .as_ref()
  62. .unwrap()
  63. .to_string()
  64. .to_snake_case())
  65. } else {
  66. Ok(self
  67. .package
  68. .as_ref()
  69. .ok_or_else(|| anyhow!("package section not provided"))?
  70. .name
  71. .to_string()
  72. .to_snake_case())
  73. }
  74. }
  75. pub fn version(&self) -> String {
  76. match &self.package {
  77. Some(package) => package.version.to_string(),
  78. _ => "0.0.0".to_string(),
  79. }
  80. }
  81. // Climbs each parent directory from the current dir until we find a Cargo.toml
  82. pub fn discover() -> Result<Option<WithPath<Manifest>>> {
  83. Manifest::discover_from_path(std::env::current_dir()?)
  84. }
  85. // Climbs each parent directory from a given starting directory until we find a Cargo.toml.
  86. pub fn discover_from_path(start_from: PathBuf) -> Result<Option<WithPath<Manifest>>> {
  87. let mut cwd_opt = Some(start_from.as_path());
  88. while let Some(cwd) = cwd_opt {
  89. for f in fs::read_dir(cwd)? {
  90. let p = f?.path();
  91. if let Some(filename) = p.file_name() {
  92. if filename.to_str() == Some("Cargo.toml") {
  93. let m = WithPath::new(Manifest::from_path(&p)?, p);
  94. return Ok(Some(m));
  95. }
  96. }
  97. }
  98. // Not found. Go up a directory level.
  99. cwd_opt = cwd.parent();
  100. }
  101. Ok(None)
  102. }
  103. }
  104. impl Deref for Manifest {
  105. type Target = cargo_toml::Manifest;
  106. fn deref(&self) -> &Self::Target {
  107. &self.0
  108. }
  109. }
  110. impl WithPath<Config> {
  111. pub fn get_program_list(&self) -> Result<Vec<PathBuf>> {
  112. // Canonicalize the workspace filepaths to compare with relative paths.
  113. let (members, exclude) = self.canonicalize_workspace()?;
  114. // Get all candidate programs.
  115. //
  116. // If [workspace.members] exists, then use that.
  117. // Otherwise, default to `programs/*`.
  118. let program_paths: Vec<PathBuf> = {
  119. if members.is_empty() {
  120. let path = self.path().parent().unwrap().join("programs");
  121. fs::read_dir(path)?
  122. .filter(|entry| entry.as_ref().map(|e| e.path().is_dir()).unwrap_or(false))
  123. .map(|dir| dir.map(|d| d.path().canonicalize().unwrap()))
  124. .collect::<Vec<Result<PathBuf, std::io::Error>>>()
  125. .into_iter()
  126. .collect::<Result<Vec<PathBuf>, std::io::Error>>()?
  127. } else {
  128. members
  129. }
  130. };
  131. // Filter out everything part of the exclude array.
  132. Ok(program_paths
  133. .into_iter()
  134. .filter(|m| !exclude.contains(m))
  135. .collect())
  136. }
  137. // TODO: this should read idl dir instead of parsing source.
  138. pub fn read_all_programs(&self) -> Result<Vec<Program>> {
  139. let mut r = vec![];
  140. for path in self.get_program_list()? {
  141. let cargo = Manifest::from_path(&path.join("Cargo.toml"))?;
  142. let lib_name = cargo.lib_name()?;
  143. let version = cargo.version();
  144. let idl = anchor_syn::idl::file::parse(path.join("src/lib.rs"), version)?;
  145. r.push(Program {
  146. lib_name,
  147. path,
  148. idl,
  149. });
  150. }
  151. Ok(r)
  152. }
  153. pub fn canonicalize_workspace(&self) -> Result<(Vec<PathBuf>, Vec<PathBuf>)> {
  154. let members = self
  155. .workspace
  156. .members
  157. .iter()
  158. .map(|m| {
  159. self.path()
  160. .parent()
  161. .unwrap()
  162. .join(m)
  163. .canonicalize()
  164. .unwrap()
  165. })
  166. .collect();
  167. let exclude = self
  168. .workspace
  169. .exclude
  170. .iter()
  171. .map(|m| {
  172. self.path()
  173. .parent()
  174. .unwrap()
  175. .join(m)
  176. .canonicalize()
  177. .unwrap()
  178. })
  179. .collect();
  180. Ok((members, exclude))
  181. }
  182. pub fn get_program(&self, name: &str) -> Result<Option<WithPath<Program>>> {
  183. for program in self.read_all_programs()? {
  184. let cargo_toml = program.path.join("Cargo.toml");
  185. if !cargo_toml.exists() {
  186. return Err(anyhow!(
  187. "Did not find Cargo.toml at the path: {}",
  188. program.path.display()
  189. ));
  190. }
  191. let p_lib_name = Manifest::from_path(&cargo_toml)?.lib_name()?;
  192. if name == p_lib_name {
  193. let path = self
  194. .path()
  195. .parent()
  196. .unwrap()
  197. .canonicalize()?
  198. .join(&program.path);
  199. return Ok(Some(WithPath::new(program, path)));
  200. }
  201. }
  202. Ok(None)
  203. }
  204. }
  205. impl<T> std::ops::Deref for WithPath<T> {
  206. type Target = T;
  207. fn deref(&self) -> &Self::Target {
  208. &self.inner
  209. }
  210. }
  211. impl<T> std::ops::DerefMut for WithPath<T> {
  212. fn deref_mut(&mut self) -> &mut Self::Target {
  213. &mut self.inner
  214. }
  215. }
  216. #[derive(Debug, Default)]
  217. pub struct Config {
  218. pub anchor_version: Option<String>,
  219. pub solana_version: Option<String>,
  220. pub registry: RegistryConfig,
  221. pub provider: ProviderConfig,
  222. pub programs: ProgramsConfig,
  223. pub scripts: ScriptsConfig,
  224. pub workspace: WorkspaceConfig,
  225. pub test: Option<Test>,
  226. }
  227. #[derive(Clone, Debug, Serialize, Deserialize)]
  228. pub struct RegistryConfig {
  229. pub url: String,
  230. }
  231. impl Default for RegistryConfig {
  232. fn default() -> Self {
  233. Self {
  234. url: "https://anchor.projectserum.com".to_string(),
  235. }
  236. }
  237. }
  238. #[derive(Debug, Default)]
  239. pub struct ProviderConfig {
  240. pub cluster: Cluster,
  241. pub wallet: WalletPath,
  242. }
  243. pub type ScriptsConfig = BTreeMap<String, String>;
  244. pub type ProgramsConfig = BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>;
  245. #[derive(Debug, Default, Clone, Serialize, Deserialize)]
  246. pub struct WorkspaceConfig {
  247. #[serde(default, skip_serializing_if = "Vec::is_empty")]
  248. pub members: Vec<String>,
  249. #[serde(default, skip_serializing_if = "Vec::is_empty")]
  250. pub exclude: Vec<String>,
  251. #[serde(default, skip_serializing_if = "String::is_empty")]
  252. pub types: String,
  253. }
  254. #[derive(ArgEnum, Clap, Clone, PartialEq, Debug)]
  255. pub enum BootstrapMode {
  256. None,
  257. Debian,
  258. }
  259. #[derive(Debug, Clone)]
  260. pub struct BuildConfig {
  261. pub verifiable: bool,
  262. pub solana_version: Option<String>,
  263. pub docker_image: String,
  264. pub bootstrap: BootstrapMode,
  265. }
  266. impl Config {
  267. pub fn docker(&self) -> String {
  268. let ver = self
  269. .anchor_version
  270. .clone()
  271. .unwrap_or_else(|| crate::DOCKER_BUILDER_VERSION.to_string());
  272. format!("projectserum/build:v{}", ver)
  273. }
  274. pub fn discover(cfg_override: &ConfigOverride) -> Result<Option<WithPath<Config>>> {
  275. Config::_discover().map(|opt| {
  276. opt.map(|mut cfg| {
  277. if let Some(cluster) = cfg_override.cluster.clone() {
  278. cfg.provider.cluster = cluster;
  279. }
  280. if let Some(wallet) = cfg_override.wallet.clone() {
  281. cfg.provider.wallet = wallet;
  282. }
  283. cfg
  284. })
  285. })
  286. }
  287. // Climbs each parent directory until we find an Anchor.toml.
  288. fn _discover() -> Result<Option<WithPath<Config>>> {
  289. let _cwd = std::env::current_dir()?;
  290. let mut cwd_opt = Some(_cwd.as_path());
  291. while let Some(cwd) = cwd_opt {
  292. for f in fs::read_dir(cwd)? {
  293. let p = f?.path();
  294. if let Some(filename) = p.file_name() {
  295. if filename.to_str() == Some("Anchor.toml") {
  296. let cfg = Config::from_path(&p)?;
  297. return Ok(Some(WithPath::new(cfg, p)));
  298. }
  299. }
  300. }
  301. cwd_opt = cwd.parent();
  302. }
  303. Ok(None)
  304. }
  305. fn from_path(p: impl AsRef<Path>) -> Result<Self> {
  306. let mut cfg_file = File::open(&p)?;
  307. let mut cfg_contents = String::new();
  308. cfg_file.read_to_string(&mut cfg_contents)?;
  309. let cfg = cfg_contents.parse()?;
  310. Ok(cfg)
  311. }
  312. pub fn wallet_kp(&self) -> Result<Keypair> {
  313. solana_sdk::signature::read_keypair_file(&self.provider.wallet.to_string())
  314. .map_err(|_| anyhow!("Unable to read keypair file"))
  315. }
  316. }
  317. #[derive(Debug, Serialize, Deserialize)]
  318. struct _Config {
  319. anchor_version: Option<String>,
  320. solana_version: Option<String>,
  321. programs: Option<BTreeMap<String, BTreeMap<String, serde_json::Value>>>,
  322. registry: Option<RegistryConfig>,
  323. provider: Provider,
  324. workspace: Option<WorkspaceConfig>,
  325. scripts: Option<ScriptsConfig>,
  326. test: Option<Test>,
  327. }
  328. #[derive(Debug, Serialize, Deserialize)]
  329. struct Provider {
  330. cluster: String,
  331. wallet: String,
  332. }
  333. impl ToString for Config {
  334. fn to_string(&self) -> String {
  335. let programs = {
  336. let c = ser_programs(&self.programs);
  337. if c.is_empty() {
  338. None
  339. } else {
  340. Some(c)
  341. }
  342. };
  343. let cfg = _Config {
  344. anchor_version: self.anchor_version.clone(),
  345. solana_version: self.solana_version.clone(),
  346. registry: Some(self.registry.clone()),
  347. provider: Provider {
  348. cluster: format!("{}", self.provider.cluster),
  349. wallet: self.provider.wallet.to_string(),
  350. },
  351. test: self.test.clone(),
  352. scripts: match self.scripts.is_empty() {
  353. true => None,
  354. false => Some(self.scripts.clone()),
  355. },
  356. programs,
  357. workspace: (!self.workspace.members.is_empty() || !self.workspace.exclude.is_empty())
  358. .then(|| self.workspace.clone()),
  359. };
  360. toml::to_string(&cfg).expect("Must be well formed")
  361. }
  362. }
  363. impl FromStr for Config {
  364. type Err = Error;
  365. fn from_str(s: &str) -> Result<Self, Self::Err> {
  366. let cfg: _Config = toml::from_str(s)
  367. .map_err(|e| anyhow::format_err!("Unable to deserialize config: {}", e.to_string()))?;
  368. Ok(Config {
  369. anchor_version: cfg.anchor_version,
  370. solana_version: cfg.solana_version,
  371. registry: cfg.registry.unwrap_or_default(),
  372. provider: ProviderConfig {
  373. cluster: cfg.provider.cluster.parse()?,
  374. wallet: shellexpand::tilde(&cfg.provider.wallet).parse()?,
  375. },
  376. scripts: cfg.scripts.unwrap_or_else(BTreeMap::new),
  377. test: cfg.test,
  378. programs: cfg.programs.map_or(Ok(BTreeMap::new()), deser_programs)?,
  379. workspace: cfg.workspace.unwrap_or_default(),
  380. })
  381. }
  382. }
  383. fn ser_programs(
  384. programs: &BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>,
  385. ) -> BTreeMap<String, BTreeMap<String, serde_json::Value>> {
  386. programs
  387. .iter()
  388. .map(|(cluster, programs)| {
  389. let cluster = cluster.to_string();
  390. let programs = programs
  391. .iter()
  392. .map(|(name, deployment)| {
  393. (
  394. name.clone(),
  395. to_value(&_ProgramDeployment::from(deployment)),
  396. )
  397. })
  398. .collect::<BTreeMap<String, serde_json::Value>>();
  399. (cluster, programs)
  400. })
  401. .collect::<BTreeMap<String, BTreeMap<String, serde_json::Value>>>()
  402. }
  403. fn to_value(dep: &_ProgramDeployment) -> serde_json::Value {
  404. if dep.path.is_none() && dep.idl.is_none() {
  405. return serde_json::Value::String(dep.address.to_string());
  406. }
  407. serde_json::to_value(dep).unwrap()
  408. }
  409. fn deser_programs(
  410. programs: BTreeMap<String, BTreeMap<String, serde_json::Value>>,
  411. ) -> Result<BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>> {
  412. programs
  413. .iter()
  414. .map(|(cluster, programs)| {
  415. let cluster: Cluster = cluster.parse()?;
  416. let programs = programs
  417. .iter()
  418. .map(|(name, program_id)| {
  419. Ok((
  420. name.clone(),
  421. ProgramDeployment::try_from(match &program_id {
  422. serde_json::Value::String(address) => _ProgramDeployment {
  423. address: address.parse()?,
  424. path: None,
  425. idl: None,
  426. },
  427. serde_json::Value::Object(_) => {
  428. serde_json::from_value(program_id.clone())
  429. .map_err(|_| anyhow!("Unable to read toml"))?
  430. }
  431. _ => return Err(anyhow!("Invalid toml type")),
  432. })?,
  433. ))
  434. })
  435. .collect::<Result<BTreeMap<String, ProgramDeployment>>>()?;
  436. Ok((cluster, programs))
  437. })
  438. .collect::<Result<BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>>>()
  439. }
  440. #[derive(Debug, Clone, Serialize, Deserialize)]
  441. pub struct Test {
  442. pub genesis: Option<Vec<GenesisEntry>>,
  443. pub clone: Option<Vec<CloneEntry>>,
  444. pub validator: Option<Validator>,
  445. pub startup_wait: Option<i32>,
  446. }
  447. #[derive(Debug, Clone, Serialize, Deserialize)]
  448. pub struct GenesisEntry {
  449. // Base58 pubkey string.
  450. pub address: String,
  451. // Filepath to the compiled program to embed into the genesis.
  452. pub program: String,
  453. }
  454. #[derive(Debug, Clone, Serialize, Deserialize)]
  455. pub struct CloneEntry {
  456. // Base58 pubkey string.
  457. pub address: String,
  458. }
  459. #[derive(Debug, Default, Clone, Serialize, Deserialize)]
  460. pub struct Validator {
  461. // IP address to bind the validator ports. [default: 0.0.0.0]
  462. #[serde(default = "default_bind_address")]
  463. pub bind_address: String,
  464. // Range to use for dynamically assigned ports. [default: 1024-65535]
  465. #[serde(skip_serializing_if = "Option::is_none")]
  466. pub dynamic_port_range: Option<String>,
  467. // Enable the faucet on this port [deafult: 9900].
  468. #[serde(skip_serializing_if = "Option::is_none")]
  469. pub faucet_port: Option<u16>,
  470. // Give the faucet address this much SOL in genesis. [default: 1000000]
  471. #[serde(skip_serializing_if = "Option::is_none")]
  472. pub faucet_sol: Option<String>,
  473. // Gossip DNS name or IP address for the validator to advertise in gossip. [default: 127.0.0.1]
  474. #[serde(skip_serializing_if = "Option::is_none")]
  475. pub gossip_host: Option<String>,
  476. // Gossip port number for the validator
  477. #[serde(skip_serializing_if = "Option::is_none")]
  478. pub gossip_port: Option<u16>,
  479. // URL for Solana's JSON RPC or moniker.
  480. #[serde(skip_serializing_if = "Option::is_none")]
  481. pub url: Option<String>,
  482. // Use DIR as ledger location
  483. #[serde(default = "default_ledger_path")]
  484. pub ledger: String,
  485. // Keep this amount of shreds in root slots. [default: 10000]
  486. #[serde(skip_serializing_if = "Option::is_none")]
  487. pub limit_ledger_size: Option<String>,
  488. // Enable JSON RPC on this port, and the next port for the RPC websocket. [default: 8899]
  489. #[serde(default = "default_rpc_port")]
  490. pub rpc_port: u16,
  491. // Override the number of slots in an epoch.
  492. #[serde(skip_serializing_if = "Option::is_none")]
  493. pub slots_per_epoch: Option<String>,
  494. // Warp the ledger to WARP_SLOT after starting the validator.
  495. #[serde(skip_serializing_if = "Option::is_none")]
  496. pub warp_slot: Option<String>,
  497. }
  498. fn default_ledger_path() -> String {
  499. ".anchor/test-ledger".to_string()
  500. }
  501. fn default_bind_address() -> String {
  502. "0.0.0.0".to_string()
  503. }
  504. fn default_rpc_port() -> u16 {
  505. 8899
  506. }
  507. #[derive(Debug, Clone)]
  508. pub struct Program {
  509. pub lib_name: String,
  510. // Canonicalized path to the program directory.
  511. pub path: PathBuf,
  512. pub idl: Option<Idl>,
  513. }
  514. impl Program {
  515. pub fn pubkey(&self) -> Result<Pubkey> {
  516. self.keypair().map(|kp| kp.pubkey())
  517. }
  518. pub fn keypair(&self) -> Result<Keypair> {
  519. let file = self.keypair_file()?;
  520. solana_sdk::signature::read_keypair_file(file.path())
  521. .map_err(|_| anyhow!("failed to read keypair for program: {}", self.lib_name))
  522. }
  523. // Lazily initializes the keypair file with a new key if it doesn't exist.
  524. pub fn keypair_file(&self) -> Result<WithPath<File>> {
  525. fs::create_dir_all("target/deploy/")?;
  526. let path = std::env::current_dir()
  527. .expect("Must have current dir")
  528. .join(format!("target/deploy/{}-keypair.json", self.lib_name));
  529. if path.exists() {
  530. return Ok(WithPath::new(File::open(&path)?, path));
  531. }
  532. let program_kp = Keypair::generate(&mut rand::rngs::OsRng);
  533. let mut file = File::create(&path)?;
  534. file.write_all(format!("{:?}", &program_kp.to_bytes()).as_bytes())?;
  535. Ok(WithPath::new(file, path))
  536. }
  537. pub fn binary_path(&self) -> PathBuf {
  538. std::env::current_dir()
  539. .expect("Must have current dir")
  540. .join(format!("target/deploy/{}.so", self.lib_name))
  541. }
  542. }
  543. #[derive(Debug, Default)]
  544. pub struct ProgramDeployment {
  545. pub address: Pubkey,
  546. pub path: Option<String>,
  547. pub idl: Option<String>,
  548. }
  549. impl TryFrom<_ProgramDeployment> for ProgramDeployment {
  550. type Error = anyhow::Error;
  551. fn try_from(pd: _ProgramDeployment) -> Result<Self, Self::Error> {
  552. Ok(ProgramDeployment {
  553. address: pd.address.parse()?,
  554. path: pd.path,
  555. idl: pd.idl,
  556. })
  557. }
  558. }
  559. #[derive(Debug, Default, Serialize, Deserialize)]
  560. pub struct _ProgramDeployment {
  561. pub address: String,
  562. pub path: Option<String>,
  563. pub idl: Option<String>,
  564. }
  565. impl From<&ProgramDeployment> for _ProgramDeployment {
  566. fn from(pd: &ProgramDeployment) -> Self {
  567. Self {
  568. address: pd.address.to_string(),
  569. path: pd.path.clone(),
  570. idl: pd.idl.clone(),
  571. }
  572. }
  573. }
  574. pub struct ProgramWorkspace {
  575. pub name: String,
  576. pub program_id: Pubkey,
  577. pub idl: Idl,
  578. }
  579. #[derive(Debug, Serialize, Deserialize)]
  580. pub struct AnchorPackage {
  581. pub name: String,
  582. pub address: String,
  583. pub idl: Option<String>,
  584. }
  585. impl AnchorPackage {
  586. pub fn from(name: String, cfg: &WithPath<Config>) -> Result<Self> {
  587. let cluster = &cfg.provider.cluster;
  588. if cluster != &Cluster::Mainnet {
  589. return Err(anyhow!("Publishing requires the mainnet cluster"));
  590. }
  591. let program_details = cfg
  592. .programs
  593. .get(cluster)
  594. .ok_or_else(|| anyhow!("Program not provided in Anchor.toml"))?
  595. .get(&name)
  596. .ok_or_else(|| anyhow!("Program not provided in Anchor.toml"))?;
  597. let idl = program_details.idl.clone();
  598. let address = program_details.address.to_string();
  599. Ok(Self { name, address, idl })
  600. }
  601. }
  602. serum_common::home_path!(WalletPath, ".config/solana/id.json");