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

Upate version api call #2899

Merged
merged 1 commit into from
Jun 15, 2019
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
10 changes: 6 additions & 4 deletions api/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod peers_api;
mod pool_api;
mod server_api;
mod transactions_api;
mod version_api;
mod utils;
mod version_api;

use self::blocks_api::BlockHandler;
use self::blocks_api::HeaderHandler;
Expand All @@ -33,10 +33,10 @@ use self::peers_api::PeersConnectedHandler;
use self::pool_api::PoolInfoHandler;
use self::pool_api::PoolPushHandler;
use self::server_api::IndexHandler;
use self::server_api::StatusHandler;
use self::server_api::KernelDownloadHandler;
use self::version_api::VersionHandler;
use self::server_api::StatusHandler;
use self::transactions_api::TxHashSetHandler;
use self::version_api::VersionHandler;
use crate::auth::{BasicAuthMiddleware, GRIN_BASIC_REALM};
use crate::chain;
use crate::p2p;
Expand Down Expand Up @@ -160,7 +160,9 @@ pub fn build_router(
let peer_handler = PeerHandler {
peers: Arc::downgrade(&peers),
};
let version_handler = VersionHandler;
let version_handler = VersionHandler {
chain: Arc::downgrade(&chain),
};

let mut router = Router::new();

Expand Down
15 changes: 11 additions & 4 deletions api/src/handlers/version_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::core::core::block::HeaderVersion;

use super::utils::w;
use crate::chain;
use crate::rest::*;
use crate::router::{Handler, ResponseFuture};
use crate::types::Version;
use crate::web::*;
use hyper::{Body, Request};
use std::sync::Weak;

const CRATE_VERSION: &'static str = env!("CARGO_PKG_VERSION");

/// Version handler. Get running node API version
/// GET /v1/version
pub struct VersionHandler;
pub struct VersionHandler {
pub chain: Weak<chain::Chain>,
}

impl VersionHandler {
fn get_version(&self) -> Result<Version, Error> {
let head = w(&self.chain)?
.head_header()
.map_err(|e| ErrorKind::Internal(format!("can't get head: {}", e)))?;

Ok(Version {
node_version: CRATE_VERSION.to_owned(),
block_header_version: HeaderVersion::default().into(),
block_header_version: head.version.into(),
})
}
}
Expand Down