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

Add print version command to the wallet #1192

Merged
merged 4 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions wallet/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023 RBB S.r.l
// opensource@mintlayer.org
// SPDX-License-Identifier: MIT
// Licensed under the MIT License;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::process::Command;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

let git_hash = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string());

if let Ok(git_hash) = git_hash {
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}
}
1 change: 1 addition & 0 deletions wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
pub mod account;
mod key_chain;
pub mod send_request;
pub mod version;
pub mod wallet;
pub mod wallet_events;

Expand Down
25 changes: 25 additions & 0 deletions wallet/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2023 RBB S.r.l
// opensource@mintlayer.org
// SPDX-License-Identifier: MIT
// Licensed under the MIT License;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// Get the Wallet version and optionally git hash
pub fn get_version() -> String {
let git_hash = env!("GIT_HASH");
let version = env!("CARGO_PKG_VERSION");

match git_hash {
"" => version.to_owned(),
git_hash => format!("{version} hash: {git_hash}"),
}
}
7 changes: 6 additions & 1 deletion wallet/wallet-cli-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use common::{
use crypto::key::{hdkd::u31::U31, PublicKey};
use p2p_types::{bannable_address::BannableAddress, ip_or_socket_address::IpOrSocketAddress};
use serialization::{hex::HexEncode, hex_encoded::HexEncoded};
use wallet::{account::Currency, wallet_events::WalletEventsNoOp};
use wallet::{account::Currency, version::get_version, wallet_events::WalletEventsNoOp};
use wallet_controller::{NodeInterface, NodeRpcClient, PeerId, DEFAULT_ACCOUNT_INDEX};

use crate::{errors::WalletCliError, CliController};
Expand Down Expand Up @@ -325,6 +325,9 @@ pub enum WalletCommand {
address: IpOrSocketAddress,
},

/// Print the version of the software and optionally the git commit hash
PrintVersion,

/// Quit the REPL
Exit,

Expand Down Expand Up @@ -1211,6 +1214,8 @@ impl CommandHandler {
Ok(ConsoleCommand::Print(addresses_table.to_string()))
}

WalletCommand::PrintVersion => Ok(ConsoleCommand::Print(get_version())),

WalletCommand::Exit => Ok(ConsoleCommand::Exit),
WalletCommand::History => Ok(ConsoleCommand::PrintHistory),
WalletCommand::ClearScreen => Ok(ConsoleCommand::ClearScreen),
Expand Down
Loading