Skip to content

Commit

Permalink
Version check fix + Rustfmt (mimblewimble#293) (mimblewimble#294)
Browse files Browse the repository at this point in the history
* Correct node version check

* rustfmt

* update pre-commit hook
  • Loading branch information
yeastplume authored Jan 14, 2020
1 parent a97dc61 commit f181a1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
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

0 comments on commit f181a1e

Please sign in to comment.