-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from eigerco/feat/66/polka-storage-provider-pr…
…int-start-time-of-the-provider Feat/66/polka storage provider print start time of the provider
- Loading branch information
Showing
18 changed files
with
523 additions
and
183 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,40 @@ | ||
use std::fmt::{self, Display, Formatter}; | ||
|
||
use chrono::{DateTime, Utc}; | ||
use clap::Parser; | ||
|
||
use crate::Error; | ||
use crate::{ | ||
cli::CliError, | ||
rpc::{methods::common::InfoRequest, version::V0, Client}, | ||
}; | ||
|
||
/// Command to display information about the storage provider. | ||
#[derive(Debug, Clone, Parser)] | ||
pub(crate) struct InfoCommand; | ||
|
||
impl InfoCommand { | ||
pub async fn run(&self) -> Result<(), Error> { | ||
// TODO(#66,@cernicc,31/05/2024): Print start time of the provider | ||
pub async fn run(&self, client: &Client<V0>) -> Result<(), CliError> { | ||
// TODO(#67,@cernicc,07/06/2024): Print polkadot address used by the provider | ||
unimplemented!() | ||
|
||
// Get server info | ||
let server_info = client.execute(InfoRequest).await?; | ||
|
||
let node_status_info = NodeStatusInfo { | ||
start_time: server_info.start_time, | ||
}; | ||
|
||
println!("{}", node_status_info); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
struct NodeStatusInfo { | ||
start_time: DateTime<Utc>, | ||
} | ||
|
||
impl Display for NodeStatusInfo { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
writeln!(f, "Started at: {}", self.start_time) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,6 @@ | ||
use std::{future::Future, net::SocketAddr, sync::Arc}; | ||
|
||
use chrono::Utc; | ||
use error::ServerError; | ||
use jsonrpsee::{ | ||
server::{Server, ServerHandle}, | ||
types::Params, | ||
RpcModule, | ||
}; | ||
use methods::create_module; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{substrate, Error}; | ||
|
||
pub mod error; | ||
mod client; | ||
pub mod methods; | ||
pub mod server; | ||
pub mod version; | ||
|
||
/// A definition of an RPC method handler which can be registered with an [`RpcModule`]. | ||
pub trait RpcMethod { | ||
/// Method name. | ||
const NAME: &'static str; | ||
/// See [`ApiVersion`]. | ||
const API_VERSION: ApiVersion; | ||
/// Successful response type. | ||
type Ok: Serialize; | ||
|
||
/// Logic for this method. | ||
fn handle( | ||
ctx: Arc<RpcServerState>, | ||
params: Params, | ||
) -> impl Future<Output = Result<Self::Ok, ServerError>> + Send; | ||
|
||
/// Register this method with an [`RpcModule`]. | ||
fn register_async(module: &mut RpcModule<RpcServerState>) -> &mut jsonrpsee::MethodCallback | ||
where | ||
Self::Ok: Clone + 'static, | ||
{ | ||
module | ||
.register_async_method(Self::NAME, move |params, ctx| async move { | ||
let ok = Self::handle(ctx, params).await?; | ||
Result::<_, jsonrpsee::types::ErrorObjectOwned>::Ok(ok) | ||
}) | ||
.expect("method should be valid") // This is safe because we know the method registered is valid. | ||
} | ||
} | ||
|
||
/// Available API versions. | ||
/// | ||
/// These are significant because they are expressed in the URL path against | ||
/// which RPC calls are made, e.g `rpc/v0` or `rpc/v1`. | ||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] | ||
pub enum ApiVersion { | ||
V0, | ||
} | ||
|
||
pub struct RpcServerState { | ||
pub start_time: chrono::DateTime<Utc>, | ||
pub substrate_client: substrate::Client, | ||
} | ||
|
||
pub async fn start_rpc( | ||
state: Arc<RpcServerState>, | ||
listen_addr: SocketAddr, | ||
) -> Result<ServerHandle, Error> { | ||
let server = Server::builder().build(listen_addr).await?; | ||
|
||
let module = create_module(state.clone()); | ||
let server_handle = server.start(module); | ||
|
||
Ok(server_handle) | ||
} | ||
pub use client::{Client, ClientError}; |
Oops, something went wrong.