Skip to content

Commit

Permalink
Merge branch 'main' into fix/invoke-view-only
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored Nov 11, 2024
2 parents 23b8d96 + f1f9583 commit 68f4fbf
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 115 deletions.
37 changes: 19 additions & 18 deletions Cargo.lock

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

14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ exclude = [
]

[workspace.package]
version = "21.5.0"
version = "22.0.0-rc.1"
rust-version = "1.81.0"

# Dependencies located in this repo:
[workspace.dependencies.soroban-cli]
version = "=21.5.0"
version = "=22.0.0-rc.1"
path = "cmd/soroban-cli"

[workspace.dependencies.soroban-spec-json]
version = "=21.5.0"
version = "=22.0.0-rc.1"
path = "./cmd/crates/soroban-spec-json"

[workspace.dependencies.soroban-spec-typescript]
version = "21.5.0"
version = "22.0.0-rc.1"
path = "./cmd/crates/soroban-spec-typescript"

[workspace.dependencies.soroban-spec-tools]
version = "21.5.0"
version = "22.0.0-rc.1"
path = "./cmd/crates/soroban-spec-tools"

# Dependencies from the rs-stellar-xdr repo:
Expand All @@ -63,9 +63,7 @@ version = "=22.0.0-rc.3"
# Dependencies from the rs-stellar-rpc-client repo:
[workspace.dependencies.soroban-rpc]
package = "stellar-rpc-client"
version = "21.4.0"
git = "https://github.com/stellar/rs-stellar-rpc-client"
rev = "7554d4c87c026313a1f5b3c7ae66a92b5ff7e091"
version = "=22.0.0-rc.1"

# Dependencies from elsewhere shared by crates:
[workspace.dependencies]
Expand Down
66 changes: 17 additions & 49 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/stellar/soroban-test"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
version = "21.5.0"
version = "22.0.0-rc.1"
edition = "2021"
rust-version.workspace = true
autobins = false
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/tests/fixtures/bye/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stellar-bye"
version = "21.5.0"
version = "22.0.0-rc.1"
edition = "2021"
publish = false

Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/tests/fixtures/hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "soroban-hello"
version = "21.5.0"
version = "22.0.0-rc.1"
edition = "2021"
publish = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_constructor"
version = "21.5.0"
version = "22.0.0-rc.1"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_custom_account"
version = "21.5.0"
version = "22.0.0-rc.1"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_custom_types"
version = "21.5.0"
version = "22.0.0-rc.1"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "test_hello_world"
version = "21.5.0"
version = "22.0.0-rc.1"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/stellar/stellar-cli"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
version = "21.5.0"
version = "22.0.0-rc.1"
edition = "2021"
rust-version.workspace = true
autobins = false
Expand Down
27 changes: 27 additions & 0 deletions cmd/soroban-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::CommandFactory;
use dotenvy::dotenv;
use tracing_subscriber::{fmt, EnvFilter};

use crate::config::Config;
use crate::print::Print;
use crate::upgrade_check::upgrade_check;
use crate::{commands, Root};
Expand Down Expand Up @@ -33,6 +34,8 @@ pub async fn main() {
}
}

set_env_from_config();

let mut root = Root::new().unwrap_or_else(|e| match e {
commands::Error::Clap(e) => {
let mut cmd = Root::command();
Expand Down Expand Up @@ -86,3 +89,27 @@ pub async fn main() {
std::process::exit(1);
}
}

// Load ~/.config/stellar/config.toml defaults as env vars.
fn set_env_from_config() {
if let Ok(config) = Config::new() {
set_env_value_from_config("STELLAR_ACCOUNT", config.defaults.identity);
set_env_value_from_config("STELLAR_NETWORK", config.defaults.network);
}
}

// Set an env var from a config file if the env var is not already set.
// Additionally, a `$NAME_SOURCE` variant will be set, which allows
// `stellar env` to properly identity the source.
fn set_env_value_from_config(name: &str, value: Option<String>) {
let Some(value) = value else {
return;
};

std::env::remove_var(format!("{name}_SOURCE"));

if std::env::var(name).is_err() {
std::env::set_var(name, value);
std::env::set_var(format!("{name}_SOURCE"), "use");
}
}
23 changes: 10 additions & 13 deletions cmd/soroban-cli/src/commands/env/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::{
commands::global,
config::{
locator::{self},
Config,
},
config::locator::{self},
print::Print,
};
use clap::Parser;
Expand All @@ -23,14 +20,13 @@ pub enum Error {
impl Cmd {
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let print = Print::new(global_args.quiet);
let config = Config::new()?;
let mut lines: Vec<(String, String)> = Vec::new();

if let Some(data) = get("STELLAR_NETWORK", config.defaults.network) {
if let Some(data) = get("STELLAR_NETWORK") {
lines.push(data);
}

if let Some(data) = get("STELLAR_ACCOUNT", config.defaults.identity) {
if let Some(data) = get("STELLAR_ACCOUNT") {
lines.push(data);
}

Expand All @@ -51,13 +47,14 @@ impl Cmd {
}
}

fn get(env_var: &str, default_value: Option<String>) -> Option<(String, String)> {
if let Ok(value) = std::env::var(env_var) {
return Some((format!("{env_var}={value}"), "env".to_string()));
}
fn get(env_var: &str) -> Option<(String, String)> {
// The _SOURCE env var is set from cmd/soroban-cli/src/cli.rs#set_env_value_from_config
let source = std::env::var(format!("{env_var}_SOURCE"))
.ok()
.unwrap_or("env".to_string());

if let Some(value) = default_value {
return Some((format!("{env_var}={value}"), "default".to_string()));
if let Ok(value) = std::env::var(env_var) {
return Some((format!("{env_var}={value}"), source));
}

None
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ For additional information see:
- Stellar Docs: https://developers.stellar.org
- Smart Contract Docs: https://developers.stellar.org/docs/build/smart-contracts/overview
- CLI Docs: https://developers.stellar.org/docs/tools/stellar-cli";
- CLI Docs: https://developers.stellar.org/docs/tools/developer-tools/cli/stellar-cli";

// long_about is shown when someone uses `--help`; short help when using `-h`
const LONG_ABOUT: &str = "
Expand Down
14 changes: 3 additions & 11 deletions cmd/soroban-cli/src/config/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use crate::xdr;

use super::{locator, secret, Config};
use super::{locator, secret};

/// Address can be either a public key or eventually an alias of a address.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -31,16 +31,8 @@ impl FromStr for Address {
type Err = Error;

fn from_str(value: &str) -> Result<Self, Self::Err> {
let mut identity = value.to_string();

if value.is_empty() {
if let Ok(config) = Config::new() {
identity = config.defaults.identity.unwrap_or_default();
}
}

Ok(xdr::MuxedAccount::from_str(&identity).map_or_else(
|_| Address::AliasOrSecret(identity.to_string()),
Ok(xdr::MuxedAccount::from_str(value).map_or_else(
|_| Address::AliasOrSecret(value.to_string()),
Address::MuxedAccount,
))
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ pub struct Args {
#[command(flatten)]
pub network: network::Args,

#[arg(
long,
visible_alias = "source",
env = "STELLAR_ACCOUNT",
default_value = ""
)]
#[arg(long, visible_alias = "source", env = "STELLAR_ACCOUNT")]
/// Account that where transaction originates from. Alias `source`.
/// Can be an identity (--source alice), a public key (--source GDKW...),
/// a muxed account (--source MDA…), a secret key (--source SC36…),
Expand Down
Loading

0 comments on commit 68f4fbf

Please sign in to comment.