Skip to content

Commit

Permalink
Upate version api call (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdm authored and yeastplume committed Jun 15, 2019
1 parent c2153fa commit 5d6defb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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

0 comments on commit 5d6defb

Please sign in to comment.