// Copyright 2015-2018 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 .
//! Deprecation notice for RPC methods.
//!
//! Displays a warning but avoids spamming the log.
use std::{
collections::HashMap,
time::{Duration, Instant},
};
use parking_lot::RwLock;
/// Deprecation messages
pub mod msgs {
pub const ACCOUNTS: Option<&str> = Some("Account management is being phased out see #9997 for alternatives.");
}
type MethodName = &'static str;
const PRINT_INTERVAL: Duration = Duration::from_secs(60);
/// Displays a deprecation notice without spamming the log.
pub struct DeprecationNotice Instant> {
now: T,
next_warning_at: RwLock>,
printer: Box) + Send + Sync>,
}
impl Default for DeprecationNotice {
fn default() -> Self {
Self::new(Instant::now, |method, more| {
let more = more.map(|x| format!(": {}", x)).unwrap_or_else(|| ".".into());
warn!(target: "rpc", "{} is deprecated and will be removed in future versions{}", method, more);
})
}
}
impl Instant> DeprecationNotice {
/// Create new deprecation notice printer with custom display and interval.
pub fn new(now: N, printer: T) -> Self where
T: Fn(MethodName, Option<&str>) + Send + Sync + 'static,
{
DeprecationNotice {
now,
next_warning_at: Default::default(),
printer: Box::new(printer),
}
}
/// Print deprecation notice for given method and with some additional details (explanations).
pub fn print<'a, T: Into