Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default network selection #5333

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ blake2 = "0.9.1"
[dev-dependencies]
tari_test_utils = { path = "../infrastructure/test_utils"}
toml = "0.5.8"

[build-dependencies]
tari_features = { version = "0.50.0-pre.0", path = "./tari_features"}
9 changes: 9 additions & 0 deletions common/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2023 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_features::resolver::build_features;

pub fn main() {
build_features();
// Build as usual
}
5 changes: 3 additions & 2 deletions common/tari_features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tari_common = { path = "../../common" }
# So you're thinking about adding a dependency here?
# This crate is utilized in the compilation of _most_ of our other crates. You're probably about
# to create a cyclic depedency. Please think hard whether this change is actually required.
26 changes: 13 additions & 13 deletions common/tari_features/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{fmt::Display, str::FromStr};

use tari_common::configuration::Network;
use std::fmt::Display;

use crate::{Feature, FEATURE_LIST};

Expand All @@ -40,6 +38,17 @@ impl Target {
Target::TestNet => "testnet",
}
}

pub fn from_network_str(value: &str) -> Self {
// The duplication of network names here isn't great but we're being lazy and non-exhaustive
// regarding the endless testnet possibilities. This minor MainNet, StageNet, and NextNet
// duplication allows us to leave the crate dependency free.
match value.to_lowercase().as_str() {
"mainnet" | "stagenet" => Target::MainNet,
"nextnet" => Target::NextNet,
_ => Target::TestNet,
}
}
}

impl Display for Target {
Expand All @@ -64,16 +73,7 @@ pub fn identify_target() -> Target {

pub fn check_envar(envar: &str) -> Option<Target> {
match std::env::var(envar) {
Ok(s) => {
let network =
Network::from_str(s.to_lowercase().as_str()).unwrap_or_else(|_| panic!("Unknown network, {}", s));
match network {
Network::MainNet | Network::StageNet => Some(Target::MainNet),
Network::NextNet => Some(Target::NextNet),
Network::LocalNet | Network::Igor | Network::Esmeralda => Some(Target::TestNet),
Network::Weatherwax | Network::Ridcully | Network::Stibbons | Network::Dibbler => None,
}
},
Ok(s) => Some(Target::from_network_str(s.to_lowercase().as_str())),
_ => None,
}
}
Expand Down