diff --git a/Cargo.lock b/Cargo.lock index 381bca2ae..f109ae3c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -594,7 +594,6 @@ dependencies = [ "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha3 0.1.0", "table 0.1.0", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -829,6 +828,17 @@ dependencies = [ "xmltree 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ipc-common-types" +version = "1.5.0" +dependencies = [ + "ethcore-ipc 1.5.0", + "ethcore-ipc-codegen 1.5.0", + "ethcore-util 1.5.0", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "isatty" version = "0.1.1" @@ -1305,7 +1315,10 @@ version = "1.5.0" dependencies = [ "ethabi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.5.0", + "ethcore-ipc 1.5.0", + "ethcore-ipc-codegen 1.5.0", "ethcore-util 1.5.0", + "ipc-common-types 1.5.0", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-hash-fetch 1.5.0", ] diff --git a/ipc-common-types/Cargo.toml b/ipc-common-types/Cargo.toml new file mode 100644 index 000000000..a483edadc --- /dev/null +++ b/ipc-common-types/Cargo.toml @@ -0,0 +1,20 @@ +[package] +description = "Types that implement IPC and are common to multiple modules." +name = "ipc-common-types" +version = "1.5.0" +license = "GPL-3.0" +authors = ["Parity Technologies "] +build = "build.rs" + +[build-dependencies] +ethcore-ipc-codegen = { path = "../ipc/codegen" } + +[dependencies] +log = "0.3" +semver = "0.5" +ethcore-ipc = { path = "../ipc/rpc" } +ethcore-util = { path = "../util" } + +[profile.release] +debug = true +lto = false diff --git a/ipc-common-types/build.rs b/ipc-common-types/build.rs new file mode 100644 index 000000000..a8e3ec1e0 --- /dev/null +++ b/ipc-common-types/build.rs @@ -0,0 +1,21 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +extern crate ethcore_ipc_codegen; + +fn main() { + ethcore_ipc_codegen::derive_binary("src/types/mod.rs.in").unwrap(); +} diff --git a/ipc-common-types/src/lib.rs b/ipc-common-types/src/lib.rs new file mode 100644 index 000000000..116921312 --- /dev/null +++ b/ipc-common-types/src/lib.rs @@ -0,0 +1,26 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Updater for Parity executables + +#[macro_use] extern crate log; +extern crate semver; +extern crate ethcore_util as util; +extern crate ethcore_ipc as ipc; + +mod types; + +pub use types::*; \ No newline at end of file diff --git a/ipc-common-types/src/types/mod.rs b/ipc-common-types/src/types/mod.rs new file mode 100644 index 000000000..57e33ad3f --- /dev/null +++ b/ipc-common-types/src/types/mod.rs @@ -0,0 +1,21 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Types used in the public api + +#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues +include!(concat!(env!("OUT_DIR"), "/mod.rs.in")); + diff --git a/ipc-common-types/src/types/mod.rs.in b/ipc-common-types/src/types/mod.rs.in new file mode 100644 index 000000000..c1177d636 --- /dev/null +++ b/ipc-common-types/src/types/mod.rs.in @@ -0,0 +1,21 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +pub mod release_track; +pub mod version_info; + +pub use release_track::{ReleaseTrack}; +pub use version_info::{VersionInfo}; \ No newline at end of file diff --git a/ipc-common-types/src/types/release_track.rs b/ipc-common-types/src/types/release_track.rs new file mode 100644 index 000000000..9b9e7d1e6 --- /dev/null +++ b/ipc-common-types/src/types/release_track.rs @@ -0,0 +1,76 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Types used in the public API + +use std::fmt; + +/// A release's track. +#[derive(PartialEq, Eq, Clone, Copy, Debug, Binary)] +pub enum ReleaseTrack { + /// Stable track. + Stable, + /// Beta track. + Beta, + /// Nightly track. + Nightly, + /// No known track. + Unknown, +} + +impl fmt::Display for ReleaseTrack { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "{}", match *self { + ReleaseTrack::Stable => "stable", + ReleaseTrack::Beta => "beta", + ReleaseTrack::Nightly => "nightly", + ReleaseTrack::Unknown => "unknown", + }) + } +} + +impl<'a> From<&'a str> for ReleaseTrack { + fn from(s: &'a str) -> Self { + match s { + "stable" => ReleaseTrack::Stable, + "beta" => ReleaseTrack::Beta, + "nightly" => ReleaseTrack::Nightly, + _ => ReleaseTrack::Unknown, + } + } +} + +impl From for ReleaseTrack { + fn from(i: u8) -> Self { + match i { + 1 => ReleaseTrack::Stable, + 2 => ReleaseTrack::Beta, + 3 => ReleaseTrack::Nightly, + _ => ReleaseTrack::Unknown, + } + } +} + +impl Into for ReleaseTrack { + fn into(self) -> u8 { + match self { + ReleaseTrack::Stable => 1, + ReleaseTrack::Beta => 2, + ReleaseTrack::Nightly => 3, + ReleaseTrack::Unknown => 0, + } + } +} diff --git a/ipc-common-types/src/types/version_info.rs b/ipc-common-types/src/types/version_info.rs new file mode 100644 index 000000000..cbffbe198 --- /dev/null +++ b/ipc-common-types/src/types/version_info.rs @@ -0,0 +1,68 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Types used in the public API + +use std::fmt; +use semver::{Version}; +use util::{H160}; +use util::misc::raw_package_info; +use release_track::ReleaseTrack; + +/// Version information of a particular release. +#[derive(Debug, Clone, PartialEq, Binary)] +pub struct VersionInfo { + /// The track on which it was released. + pub track: ReleaseTrack, + /// The version. + pub version: Version, + /// The (SHA1?) 160-bit hash of this build's code base. + pub hash: H160, +} + +impl fmt::Display for VersionInfo { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "{}.{}.{}-{}-{}", self.version.major, self.version.minor, self.version.patch, self.track, self.hash) + } +} + +impl VersionInfo { + /// Get information for this (currently running) binary. + pub fn this() -> Self { + let raw = raw_package_info(); + VersionInfo { + track: raw.0.into(), + version: { let mut v = Version::parse(raw.1).expect("Environment variables are known to be valid; qed"); v.build = vec![]; v.pre = vec![]; v }, + hash: raw.2.into(), + } + } + + /// Compose the information from the provided raw fields. + pub fn from_raw(semver: u32, track: u8, hash: H160) -> Self { + let t = track.into(); + VersionInfo { + version: Version { + major: (semver >> 16) as u64, + minor: ((semver >> 8) & 0xff) as u64, + patch: (semver & 0xff) as u64, + build: vec![], + pre: vec![], + }, + track: t, + hash: hash, + } + } +} diff --git a/ipc/codegen/src/serialization.rs b/ipc/codegen/src/serialization.rs index c7d288010..983d63f11 100644 --- a/ipc/codegen/src/serialization.rs +++ b/ipc/codegen/src/serialization.rs @@ -286,7 +286,6 @@ fn binary_expr_struct( post_write_stmts.push(quote_stmt!(cx, if $range_ident.end - $range_ident.start > 0 { if let Err(e) = $member_expr .to_bytes(&mut buffer[$range_ident], length_stack) { - warn!(target: "ipc", $error_message_literal); return Err(e) }; } diff --git a/ipc/rpc/src/binary.rs b/ipc/rpc/src/binary.rs index 3c7060260..eed894fce 100644 --- a/ipc/rpc/src/binary.rs +++ b/ipc/rpc/src/binary.rs @@ -804,6 +804,17 @@ binary_fixed_size!(H512); binary_fixed_size!(H2048); binary_fixed_size!(Address); binary_fixed_size!(BinHandshake); +binary_fixed_size!(BinVersion); + +impl BinaryConvertable for ::semver::Version { + fn from_bytes(bytes: &[u8], length_stack: &mut ::std::collections::VecDeque) -> Result { + BinVersion::from_bytes(bytes, length_stack).map(BinVersion::to_semver) + } + + fn to_bytes(&self, buffer: &mut [u8], length_stack: &mut ::std::collections::VecDeque) -> Result<(), BinaryConvertError> { + BinVersion::from(self.clone()).to_bytes(buffer, length_stack) + } +} #[test] fn vec_serialize() { diff --git a/ipc/rpc/src/lib.rs b/ipc/rpc/src/lib.rs index c17acff98..e6586397a 100644 --- a/ipc/rpc/src/lib.rs +++ b/ipc/rpc/src/lib.rs @@ -24,4 +24,4 @@ extern crate ethcore_util as util; pub mod interface; pub mod binary; pub use interface::{IpcInterface, IpcSocket, invoke, IpcConfig, Handshake, Error, WithSocket}; -pub use binary::{BinaryConvertable, BinaryConvertError, BinHandshake}; +pub use binary::{BinaryConvertable, BinaryConvertError, BinVersion, BinHandshake}; diff --git a/updater/Cargo.toml b/updater/Cargo.toml index a018f5f29..b97e057d7 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -4,6 +4,10 @@ name = "parity-updater" version = "1.5.0" license = "GPL-3.0" authors = ["Parity Technologies "] +build = "build.rs" + +[build-dependencies] +ethcore-ipc-codegen = { path = "../ipc/codegen" } [dependencies] log = "0.3" @@ -11,6 +15,8 @@ ethabi = "0.2.2" ethcore = { path = "../ethcore" } ethcore-util = { path = "../util" } parity-hash-fetch = { path = "../hash-fetch" } +ipc-common-types = { path = "../ipc-common-types" } +ethcore-ipc = { path = "../ipc/rpc" } [profile.release] debug = true diff --git a/updater/build.rs b/updater/build.rs new file mode 100644 index 000000000..a4d42d43a --- /dev/null +++ b/updater/build.rs @@ -0,0 +1,22 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +extern crate ethcore_ipc_codegen; + +fn main() { + ethcore_ipc_codegen::derive_binary("src/types/mod.rs.in").unwrap(); + ethcore_ipc_codegen::derive_ipc_cond("src/service.rs", cfg!(feature="ipc")).unwrap(); +} diff --git a/updater/src/lib.rs b/updater/src/lib.rs index 08ed57717..1567a88a0 100644 --- a/updater/src/lib.rs +++ b/updater/src/lib.rs @@ -18,13 +18,21 @@ #[macro_use] extern crate log; extern crate ethcore_util as util; +extern crate ipc_common_types; extern crate parity_hash_fetch as hash_fetch; extern crate ethcore; extern crate ethabi; +extern crate ethcore_ipc as ipc; mod updater; mod operations; -mod service; +mod types; -pub use service::{Service, ReleaseInfo, OperationsInfo, CapState}; +mod service { + #![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues + include!(concat!(env!("OUT_DIR"), "/service.rs")); +} + +pub use service::{Service}; +pub use types::all::{ReleaseInfo, OperationsInfo, CapState, VersionInfo, ReleaseTrack}; pub use updater::{Updater, UpdateFilter, UpdatePolicy}; \ No newline at end of file diff --git a/updater/src/service.rs b/updater/src/service.rs index 2343a95f7..ffc905fb7 100644 --- a/updater/src/service.rs +++ b/updater/src/service.rs @@ -14,54 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::{H256}; -use util::misc::{VersionInfo}; - -/// Information regarding a particular release of Parity -#[derive(Debug, Clone, PartialEq)] -pub struct ReleaseInfo { - /// Information on the version. - pub version: VersionInfo, - /// Does this release contain critical security updates? - pub is_critical: bool, - /// The latest fork that this release can handle. - pub fork: u64, - /// Our platform's binary, if known. - pub binary: Option, -} - -/// Information on our operations environment. -#[derive(Debug, Clone, PartialEq)] -pub struct OperationsInfo { - /// Our blockchain's latest fork. - pub fork: u64, - - /// Last fork our client supports, if known. - pub this_fork: Option, - - /// Information on our track's latest release. - pub track: ReleaseInfo, - /// Information on our minor version's latest release. - pub minor: Option, -} - -/// Information on the current version's consensus capabililty. -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum CapState { - /// Unknown. - Unknown, - /// Capable of consensus indefinitely. - Capable, - /// Capable of consensus up until a definite block. - CapableUntil(u64), - /// Incapable of consensus since a particular block. - IncapableSince(u64), -} - -impl Default for CapState { - fn default() -> Self { CapState::Unknown } -} +use types::all::{CapState, ReleaseInfo, OperationsInfo}; +use ipc_common_types::VersionInfo; +#[ipc(client_ident="RemoteUpdater")] pub trait Service: Send + Sync { /// Is the currently running client capable of supporting the current chain? /// We default to true if there's no clear information. diff --git a/updater/src/types/all.rs b/updater/src/types/all.rs new file mode 100644 index 000000000..5a602afcd --- /dev/null +++ b/updater/src/types/all.rs @@ -0,0 +1,65 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Types used in the public API + +use util::{H256}; +pub use ipc_common_types::{VersionInfo, ReleaseTrack}; + +/// Information regarding a particular release of Parity +#[derive(Debug, Clone, PartialEq, Binary)] +pub struct ReleaseInfo { + /// Information on the version. + pub version: VersionInfo, + /// Does this release contain critical security updates? + pub is_critical: bool, + /// The latest fork that this release can handle. + pub fork: u64, + /// Our platform's binary, if known. + pub binary: Option, +} + +/// Information on our operations environment. +#[derive(Debug, Clone, PartialEq, Binary)] +pub struct OperationsInfo { + /// Our blockchain's latest fork. + pub fork: u64, + + /// Last fork our client supports, if known. + pub this_fork: Option, + + /// Information on our track's latest release. + pub track: ReleaseInfo, + /// Information on our minor version's latest release. + pub minor: Option, +} + +/// Information on the current version's consensus capabililty. +#[derive(Debug, Clone, Copy, PartialEq, Binary)] +pub enum CapState { + /// Unknown. + Unknown, + /// Capable of consensus indefinitely. + Capable, + /// Capable of consensus up until a definite block. + CapableUntil(u64), + /// Incapable of consensus since a particular block. + IncapableSince(u64), +} + +impl Default for CapState { + fn default() -> Self { CapState::Unknown } +} diff --git a/updater/src/types/mod.rs b/updater/src/types/mod.rs new file mode 100644 index 000000000..57e33ad3f --- /dev/null +++ b/updater/src/types/mod.rs @@ -0,0 +1,21 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Types used in the public api + +#![allow(dead_code, unused_assignments, unused_variables)] // codegen issues +include!(concat!(env!("OUT_DIR"), "/mod.rs.in")); + diff --git a/updater/src/types/mod.rs.in b/updater/src/types/mod.rs.in new file mode 100644 index 000000000..10037f932 --- /dev/null +++ b/updater/src/types/mod.rs.in @@ -0,0 +1,17 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +pub mod all; diff --git a/updater/src/updater.rs b/updater/src/updater.rs index f0226f9e0..3b793623e 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -18,12 +18,14 @@ use std::sync::{Arc, Weak}; use std::{fs, env}; use std::io::Write; use std::path::{PathBuf}; -use util::misc::{VersionInfo, ReleaseTrack/*, platform*/}; +//use util::misc::platform; +use ipc_common_types::{VersionInfo, ReleaseTrack}; use util::{Address, H160, H256, FixedHash, Mutex, Bytes}; use ethcore::client::{BlockId, BlockChainClient, ChainNotify}; use hash_fetch::{self as fetch, HashFetch}; use operations::Operations; -use service::{Service, ReleaseInfo, OperationsInfo, CapState}; +use service::{Service}; +use types::all::{ReleaseInfo, OperationsInfo, CapState}; /// Filter for releases. #[derive(Debug, Eq, PartialEq, Clone)] diff --git a/util/Cargo.toml b/util/Cargo.toml index c9f347bfb..594024f3f 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -37,7 +37,6 @@ tiny-keccak= "1.0" ethcore-bloom-journal = { path = "bloom" } regex = "0.1" lru-cache = "0.1.0" -semver = "0.5" [features] default = [] diff --git a/util/src/lib.rs b/util/src/lib.rs index 74e4418ce..e37214879 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -106,7 +106,6 @@ extern crate tiny_keccak; extern crate rlp; extern crate regex; extern crate lru_cache; -extern crate semver; #[macro_use] extern crate heapsize; diff --git a/util/src/misc.rs b/util/src/misc.rs index eea443396..0c3a32554 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -17,7 +17,6 @@ //! Diff misc. use common::*; -use semver::{Identifier, Version}; use rlp::{Stream, RlpStream}; use target_info::Target; @@ -33,107 +32,6 @@ pub enum Filth { Dirty, } -/// A release's track. -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub enum ReleaseTrack { - /// Stable track. - Stable, - /// Beta track. - Beta, - /// Nightly track. - Nightly, - /// No known track. - Unknown, -} - -impl fmt::Display for ReleaseTrack { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{}", match *self { - ReleaseTrack::Stable => "stable", - ReleaseTrack::Beta => "beta", - ReleaseTrack::Nightly => "nightly", - ReleaseTrack::Unknown => "unknown", - }) - } -} - -impl<'a> From<&'a str> for ReleaseTrack { - fn from(s: &'a str) -> Self { - match s { - "stable" => ReleaseTrack::Stable, - "beta" => ReleaseTrack::Beta, - "nightly" => ReleaseTrack::Nightly, - _ => ReleaseTrack::Unknown, - } - } -} - -impl From for ReleaseTrack { - fn from(i: u8) -> Self { - match i { - 1 => ReleaseTrack::Stable, - 2 => ReleaseTrack::Beta, - 3 => ReleaseTrack::Nightly, - _ => ReleaseTrack::Unknown, - } - } -} - -impl Into for ReleaseTrack { - fn into(self) -> u8 { - match self { - ReleaseTrack::Stable => 1, - ReleaseTrack::Beta => 2, - ReleaseTrack::Nightly => 3, - ReleaseTrack::Unknown => 0, - } - } -} - -/// Version information of a particular release. -#[derive(Debug, Clone, PartialEq)] -pub struct VersionInfo { - /// The track on which it was released. - pub track: ReleaseTrack, - /// The version. - pub version: Version, - /// The (SHA1?) 160-bit hash of this build's code base. - pub hash: H160, -} - -impl fmt::Display for VersionInfo { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{}-{}", self.version, self.hash) - } -} - -impl VersionInfo { - /// Get information for this (currently running) binary. - pub fn this() -> Self { - VersionInfo { - track: env!["CARGO_PKG_VERSION_PRE"].into(), - version: Version::parse(env!["CARGO_PKG_VERSION"]).expect("Environment variables are known to be valid; qed"), - hash: sha().into(), - } - } - - /// Compose the information from the provided raw fields. - pub fn from_raw(semver: u32, track: u8, hash: H160) -> Self { - let t = track.into(); - VersionInfo { - version: Version { - major: (semver >> 16) as u64, - minor: ((semver >> 8) & 0xff) as u64, - patch: (semver & 0xff) as u64, - build: vec![], - pre: vec![Identifier::AlphaNumeric(format!("{}", t))] - }, - track: t, - hash: hash, - } - } -} - /// Get the platform identifier. pub fn platform() -> String { let env = Target::env(); @@ -163,3 +61,8 @@ pub fn version_data() -> Bytes { s.append(&&Target::os()[0..2]); s.out() } + +/// Provide raw information on the package. +pub fn raw_package_info() -> (&'static str, &'static str, &'static str) { + (env!["CARGO_PKG_VERSION_PRE"], env!["CARGO_PKG_VERSION"], sha()) +} \ No newline at end of file