Version check fix + Rustfmt (#293) (#294)

* Correct node version check

* rustfmt

* update pre-commit hook
This commit is contained in:
Yeastplume 2020-01-14 15:50:49 +00:00 committed by GitHub
parent a97dc61725
commit f181a1e71d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 33 deletions

View file

@ -22,38 +22,29 @@ if [ $? != 0 ]; then
exit 1 exit 1
fi fi
result=0
problem_files=() problem_files=()
printf "[pre_commit] rustfmt " # first collect all the files that need reformatting
for file in $(git diff --name-only --cached); do for file in $(git diff --name-only --cached); do
if [ ${file: -3} == ".rs" ]; then if [ ${file: -3} == ".rs" ]; then
# first collect all the files that need reformatting
rustfmt --check $file &>/dev/null rustfmt --check $file &>/dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
problem_files+=($file) problem_files+=($file)
result=1
fi fi
fi fi
done done
# now reformat all the files that need reformatting if [ ${#problem_files[@]} == 0 ]; then
for file in ${problem_files[@]}; do # nothing to do
rustfmt $file printf "[pre_commit] rustfmt \033[0;32mok\033[0m \n"
done else
# reformat the files that need it and re-stage them.
# and let the user know what just happened (and which files were affected) printf "[pre_commit] the following files were rustfmt'd before commit: \n"
printf "\033[0;32mok\033[0m \n" for file in ${problem_files[@]}; do
if [ $result != 0 ]; then rustfmt $file
# printf "\033[0;31mrustfmt\033[0m \n" git add $file
printf "[pre_commit] the following files were rustfmt'd (not yet committed): \n" printf "\033[0;32m $file\033[0m \n"
done
for file in ${problem_files[@]}; do
printf "\033[0;31m $file\033[0m \n"
done
fi fi
exit 0 exit 0
# to actually fail the build on rustfmt failure -
# exit $result

View file

@ -20,7 +20,7 @@ use semver::Version;
use std::thread; use std::thread;
use std::time::Duration; 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>( pub fn wallet_command<C>(
wallet_args: &ArgMatches<'_>, wallet_args: &ArgMatches<'_>,
@ -36,24 +36,18 @@ where
let tor_config = config.members.unwrap().tor; let tor_config = config.members.unwrap().tor;
// Check the node version info, and exit with report if we're not compatible // 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) let global_wallet_args = wallet_args::parse_global_args(&wallet_config, &wallet_args)
.expect("Can't read configuration file"); .expect("Can't read configuration file");
node_client.set_node_api_secret(global_wallet_args.node_api_secret.clone()); 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 // 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() { 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) { if Version::parse(&v.node_version) < Version::parse(MIN_COMPAT_NODE_VERSION) {
let version = if v.node_version == "1.0.0" { println!("The Grin Node in use (version {}) is outdated and incompatible with this wallet version.", v.node_version);
"1.x.x series" println!(
} else { "Please update the node to version {} or later and try again.",
&v.node_version MIN_COMPAT_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.");
return 1; return 1;
} }
} }