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

Version check fix + Rustfmt #293

Merged
merged 3 commits into from
Jan 14, 2020
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
33 changes: 12 additions & 21 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,29 @@ if [ $? != 0 ]; then
exit 1
fi

result=0
problem_files=()

printf "[pre_commit] rustfmt "

# first collect all the files that need reformatting
for file in $(git diff --name-only --cached); do
if [ ${file: -3} == ".rs" ]; then
# first collect all the files that need reformatting
rustfmt --check $file &>/dev/null
if [ $? != 0 ]; then
problem_files+=($file)
result=1
fi
fi
done

# now reformat all the files that need reformatting
for file in ${problem_files[@]}; do
rustfmt $file
done

# and let the user know what just happened (and which files were affected)
printf "\033[0;32mok\033[0m \n"
if [ $result != 0 ]; then
# printf "\033[0;31mrustfmt\033[0m \n"
printf "[pre_commit] the following files were rustfmt'd (not yet committed): \n"

for file in ${problem_files[@]}; do
printf "\033[0;31m $file\033[0m \n"
done
if [ ${#problem_files[@]} == 0 ]; then
# nothing to do
printf "[pre_commit] rustfmt \033[0;32mok\033[0m \n"
else
# reformat the files that need it and re-stage them.
printf "[pre_commit] the following files were rustfmt'd before commit: \n"
for file in ${problem_files[@]}; do
rustfmt $file
git add $file
printf "\033[0;32m $file\033[0m \n"
done
fi

exit 0
# to actually fail the build on rustfmt failure -
# exit $result
18 changes: 6 additions & 12 deletions src/cmd/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use semver::Version;
use std::thread;
use std::time::Duration;

const MIN_COMPAT_NODE_VERSION: &str = "2.0.0-beta.1";
const MIN_COMPAT_NODE_VERSION: &str = "3.0.0";

pub fn wallet_command<C>(
wallet_args: &ArgMatches<'_>,
Expand All @@ -36,24 +36,18 @@ where
let tor_config = config.members.unwrap().tor;

// Check the node version info, and exit with report if we're not compatible
//let mut node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None);
let global_wallet_args = wallet_args::parse_global_args(&wallet_config, &wallet_args)
.expect("Can't read configuration file");
node_client.set_node_api_secret(global_wallet_args.node_api_secret.clone());

// This will also cache the node version info for calls to foreign API check middleware
if let Some(v) = node_client.clone().get_version_info() {
// Isn't going to happen just yet (as of 2.0.0) but keep this here for
// the future. the nodeclient's get_version_info will return 1.0 if
// it gets a 404 for the version function
if Version::parse(&v.node_version) < Version::parse(MIN_COMPAT_NODE_VERSION) {
let version = if v.node_version == "1.0.0" {
"1.x.x series"
} else {
&v.node_version
};
println!("The Grin Node in use (version {}) is outdated and incompatible with this wallet version.", version);
println!("Please update the node to version 2.0.0 or later and try again.");
println!("The Grin Node in use (version {}) is outdated and incompatible with this wallet version.", v.node_version);
println!(
"Please update the node to version {} or later and try again.",
MIN_COMPAT_NODE_VERSION
);
return 1;
}
}
Expand Down