Skip to content

Commit

Permalink
Add url into config, add payer to argumenta, use default solana payer…
Browse files Browse the repository at this point in the history
… if missing in args and config #54
  • Loading branch information
Semen Medvedev committed Jun 29, 2022
1 parent 36f5c1a commit 1055425
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions launch-script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions launch-script/src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub struct ConfigFile {
#[serde(default)]
pub payer: String,

#[serde(default)]
pub url: String,

pub creator: String,
pub community_mint: String,

Expand Down
41 changes: 34 additions & 7 deletions launch-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -102,7 +106,6 @@ fn main() {
.long("config")
.short("c")
.takes_value(true)
//.global(true)
.required(true)
.help("Configuration file")
)
Expand All @@ -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")
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 1 addition & 4 deletions testing.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{

"payer": "artifacts/payer.keypair",
"voters-dir": "artifacts/voters/",

"url": "http://localhost:8899",
"creator": "5mAkTXJMyFxvEeUNpfiwAqUfD3qRSRmdh6j6YgXDwqrm",
"community-mint": "EjLGfD8mpxKLwGDi8AiTisAbGtWWM2L3htkJ6MpvS8Hk",
"governance-program": "82pQHEmBbW6CQS8GzLP3WE2pCgMUPSW2XzpuSih3aFDk",
Expand Down

0 comments on commit 1055425

Please sign in to comment.