From 10554253643f1b5598e4ae6591feba83d21defe1 Mon Sep 17 00:00:00 2001 From: Semen Medvedev Date: Wed, 29 Jun 2022 12:07:40 +0700 Subject: [PATCH] Add url into config, add payer to argumenta, use default solana payer if missing in args and config #54 --- Cargo.lock | 1 + launch-script/Cargo.toml | 1 + launch-script/src/config_file.rs | 3 +++ launch-script/src/main.rs | 41 ++++++++++++++++++++++++++------ testing.cfg | 5 +--- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 427af1f..84d39bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1527,6 +1527,7 @@ dependencies = [ "serde", "serde_json", "solana-clap-utils", + "solana-cli-config", "solana-client", "solana-sdk", "spl-associated-token-account 1.0.5", diff --git a/launch-script/Cargo.toml b/launch-script/Cargo.toml index 3a15651..cc65bdd 100644 --- a/launch-script/Cargo.toml +++ b/launch-script/Cargo.toml @@ -11,6 +11,7 @@ goblin = "0.4.2" solana-sdk = "1.10.16" solana-client = "1.10.16" solana-clap-utils = "1.10.16" +solana-cli-config = "1.10.16" borsh = "0.9.1" log = "0.4.11" clap = "2.33.3" diff --git a/launch-script/src/config_file.rs b/launch-script/src/config_file.rs index 4014439..f344532 100644 --- a/launch-script/src/config_file.rs +++ b/launch-script/src/config_file.rs @@ -9,6 +9,9 @@ pub struct ConfigFile { #[serde(default)] pub payer: String, + #[serde(default)] + pub url: String, + pub creator: String, pub community_mint: String, diff --git a/launch-script/src/main.rs b/launch-script/src/main.rs index 24ca363..16385ea 100644 --- a/launch-script/src/main.rs +++ b/launch-script/src/main.rs @@ -49,6 +49,10 @@ pub mod prelude { pub use std::path::Path; } use prelude::*; +use solana_cli_config::{ + Config as SolanaCliConfig, + CONFIG_FILE as SOLANA_CLI_CONFIG_FILE, +}; pub const TOKEN_MULT: u64 = u64::pow(10, 9); pub const REALM_NAME: &str = "NEON"; @@ -102,7 +106,6 @@ fn main() { .long("config") .short("c") .takes_value(true) - //.global(true) .required(true) .help("Configuration file") ) @@ -112,8 +115,14 @@ fn main() { .short("u") .takes_value(true) .global(true) - .default_value("http://localhost:8899") - .help("Url to solana cluster") + .help("Url to solana cluster [overrides 'url' value in config file, default: http://localhost:8899]") + ) + .arg( + Arg::with_name("payer") + .long("payer") + .takes_value(true) + .global(true) + .help("Path to payer keypair [overrides 'payer' value in config file, default: solana cli keypair]") ) .subcommand(SubCommand::with_name("environment") @@ -307,14 +316,32 @@ fn main() { let config_file = std::fs::File::open(matches.value_of("config").unwrap()) .expect("config file should exists"); - let config: ConfigFile = serde_json::from_reader(config_file) - .expect("file should be proper JSON"); + let config = { + let mut config: ConfigFile = serde_json::from_reader(config_file) + .expect("file should be proper JSON"); + + if let Some(payer) = matches.value_of("payer") { + config.payer = payer.to_string(); + } else if config.payer.is_empty() { + let solana_config = SolanaCliConfig::load(SOLANA_CLI_CONFIG_FILE.as_ref().unwrap()) + .expect("Solana cli config file"); + config.payer = solana_config.keypair_path; + } + + if let Some(url) = matches.value_of("url") { + config.url = url.to_string(); + } else if config.url.is_empty() { + config.url = "http://localhost:8899".to_string(); + } + + config + }; + println!("ConfigFile: {:#?}", config); let wallet = Wallet::new_from_config(&config).expect("invalid wallet configuration"); wallet.display(); - let url = matches.value_of("url").unwrap(); - let client = Client::new(url, &wallet.payer_keypair); + let client = Client::new(&config.url, &wallet.payer_keypair); let send_trx: bool = matches.is_present("send_trx"); let verbose: bool = matches.is_present("verbose"); diff --git a/testing.cfg b/testing.cfg index 5db7736..7219c50 100644 --- a/testing.cfg +++ b/testing.cfg @@ -1,8 +1,5 @@ { - - "payer": "artifacts/payer.keypair", - "voters-dir": "artifacts/voters/", - + "url": "http://localhost:8899", "creator": "5mAkTXJMyFxvEeUNpfiwAqUfD3qRSRmdh6j6YgXDwqrm", "community-mint": "EjLGfD8mpxKLwGDi8AiTisAbGtWWM2L3htkJ6MpvS8Hk", "governance-program": "82pQHEmBbW6CQS8GzLP3WE2pCgMUPSW2XzpuSih3aFDk",