2016-11-18 12:14:52 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
use std::sync::{Arc, Weak};
|
2016-12-11 03:33:10 +01:00
|
|
|
use std::{fs, env};
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::{PathBuf};
|
2016-12-09 19:02:42 +01:00
|
|
|
use util::misc::{VersionInfo, ReleaseTrack/*, platform*/};
|
2016-12-11 02:02:40 +01:00
|
|
|
use util::{Address, H160, H256, FixedHash, Mutex, Bytes};
|
2016-12-10 23:58:39 +01:00
|
|
|
use super::operations::Operations;
|
2016-12-11 02:02:40 +01:00
|
|
|
use ethcore::client::{BlockId, BlockChainClient, ChainNotify};
|
|
|
|
use hash_fetch::{self as fetch, HashFetch};
|
2016-11-22 10:24:22 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Filter for releases.
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
|
|
pub enum UpdateFilter {
|
|
|
|
/// All releases following the same track.
|
|
|
|
All,
|
|
|
|
/// As with `All`, but only those which are known to be critical.
|
|
|
|
Critical,
|
|
|
|
/// None.
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The policy for auto-updating.
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
|
|
|
pub struct UpdatePolicy {
|
|
|
|
/// Download potential updates.
|
|
|
|
pub enable_downloading: bool,
|
|
|
|
/// Which of those downloaded should be automatically installed.
|
|
|
|
pub filter: UpdateFilter,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for UpdatePolicy {
|
|
|
|
fn default() -> Self {
|
|
|
|
UpdatePolicy {
|
|
|
|
enable_downloading: false,
|
|
|
|
filter: UpdateFilter::None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Information regarding a particular release of Parity
|
2016-11-25 15:43:49 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2016-11-22 10:24:22 +01:00
|
|
|
pub struct ReleaseInfo {
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Information on the version.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub version: VersionInfo,
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Does this release contain critical security updates?
|
2016-11-25 15:43:49 +01:00
|
|
|
pub is_critical: bool,
|
2016-12-10 23:58:39 +01:00
|
|
|
/// The latest fork that this release can handle.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub fork: u64,
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Our platform's binary, if known.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub binary: Option<H256>,
|
|
|
|
}
|
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Information on our operations environment.
|
2016-11-25 15:43:49 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct OperationsInfo {
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Our blockchain's latest fork.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub fork: u64,
|
2016-11-22 10:24:22 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Last fork our client supports, if known.
|
|
|
|
pub this_fork: Option<u64>,
|
|
|
|
|
|
|
|
/// Information on our track's latest release.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub track: ReleaseInfo,
|
2016-12-10 23:58:39 +01:00
|
|
|
/// Information on our minor version's latest release.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub minor: Option<ReleaseInfo>,
|
2016-11-22 10:24:22 +01:00
|
|
|
}
|
2016-11-18 12:14:52 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct UpdaterState {
|
|
|
|
latest: Option<OperationsInfo>,
|
|
|
|
|
|
|
|
fetching: Option<ReleaseInfo>,
|
|
|
|
ready: Option<ReleaseInfo>,
|
|
|
|
installed: Option<ReleaseInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Service for checking for updates and determining whether we can achieve consensus.
|
2016-11-18 12:14:52 +01:00
|
|
|
pub struct Updater {
|
2016-12-10 23:58:39 +01:00
|
|
|
// Useful environmental stuff.
|
2016-11-24 17:19:48 +01:00
|
|
|
update_policy: UpdatePolicy,
|
2016-12-11 02:02:40 +01:00
|
|
|
weak_self: Mutex<Weak<Updater>>,
|
|
|
|
client: Weak<BlockChainClient>,
|
2016-12-11 02:39:56 +01:00
|
|
|
fetcher: Mutex<Option<fetch::Client>>,
|
2016-12-10 23:58:39 +01:00
|
|
|
operations: Mutex<Option<Operations>>,
|
2016-12-11 02:02:40 +01:00
|
|
|
exit_handler: Mutex<Option<Box<Fn() + 'static + Send>>>,
|
2016-11-18 12:14:52 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// Our version info (static)
|
|
|
|
this: VersionInfo,
|
2016-11-25 15:43:49 +01:00
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// All the other info - this changes so leave it behind a Mutex.
|
|
|
|
state: Mutex<UpdaterState>,
|
2016-11-20 13:18:56 +01:00
|
|
|
}
|
|
|
|
|
2016-11-25 15:43:49 +01:00
|
|
|
const CLIENT_ID: &'static str = "parity";
|
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
2016-12-09 19:02:42 +01:00
|
|
|
fn platform() -> String {
|
|
|
|
"test".to_owned()
|
|
|
|
}
|
|
|
|
|
2016-11-18 12:14:52 +01:00
|
|
|
impl Updater {
|
2016-12-10 23:58:39 +01:00
|
|
|
pub fn new(client: Weak<BlockChainClient>, update_policy: UpdatePolicy) -> Arc<Self> {
|
2016-11-22 10:24:22 +01:00
|
|
|
let mut u = Updater {
|
2016-11-24 17:19:48 +01:00
|
|
|
update_policy: update_policy,
|
2016-12-11 02:02:40 +01:00
|
|
|
weak_self: Mutex::new(Default::default()),
|
2016-12-10 23:58:39 +01:00
|
|
|
client: client.clone(),
|
2016-12-11 02:39:56 +01:00
|
|
|
fetcher: Mutex::new(None),
|
2016-12-10 23:58:39 +01:00
|
|
|
operations: Mutex::new(None),
|
|
|
|
exit_handler: Mutex::new(None),
|
2016-11-22 10:24:22 +01:00
|
|
|
this: VersionInfo::this(),
|
2016-12-10 23:58:39 +01:00
|
|
|
state: Mutex::new(Default::default()),
|
2016-11-22 10:24:22 +01:00
|
|
|
};
|
2016-11-24 17:19:48 +01:00
|
|
|
|
|
|
|
// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
2016-11-22 10:24:22 +01:00
|
|
|
if u.this.track == ReleaseTrack::Unknown {
|
|
|
|
u.this.track = ReleaseTrack::Nightly;
|
2016-11-24 17:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 02:39:56 +01:00
|
|
|
let r = Arc::new(u);
|
|
|
|
*r.fetcher.lock() = Some(fetch::Client::new(r.clone()));
|
2016-12-11 02:02:40 +01:00
|
|
|
*r.weak_self.lock() = Arc::downgrade(&r);
|
2016-12-10 23:58:39 +01:00
|
|
|
r
|
2016-11-18 12:14:52 +01:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:19:48 +01:00
|
|
|
/// Is the currently running client capable of supporting the current chain?
|
2016-11-30 10:16:18 +01:00
|
|
|
/// `Some` answer or `None` if information on the running client is not available.
|
2016-11-24 17:19:48 +01:00
|
|
|
pub fn is_capable(&self) -> Option<bool> {
|
2016-12-10 23:58:39 +01:00
|
|
|
self.state.lock().latest.as_ref().and_then(|latest| {
|
|
|
|
latest.this_fork.map(|this_fork| {
|
2016-11-24 17:19:48 +01:00
|
|
|
let current_number = self.client.upgrade().map_or(0, |c| c.block_number(BlockId::Latest).unwrap_or(0));
|
2016-11-30 10:16:18 +01:00
|
|
|
this_fork >= latest.fork || current_number < latest.fork
|
2016-11-24 17:19:48 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The release which is ready to be upgraded to, if any. If this returns `Some`, then
|
|
|
|
/// `execute_upgrade` may be called.
|
2016-12-09 19:02:42 +01:00
|
|
|
pub fn upgrade_ready(&self) -> Option<ReleaseInfo> {
|
2016-12-10 23:58:39 +01:00
|
|
|
self.state.lock().ready.clone()
|
2016-12-09 20:40:24 +01:00
|
|
|
}
|
|
|
|
|
2016-11-24 17:19:48 +01:00
|
|
|
/// Actually upgrades the client. Assumes that the binary has been downloaded.
|
2016-11-30 10:16:18 +01:00
|
|
|
/// @returns `true` on success.
|
2016-12-11 02:02:40 +01:00
|
|
|
pub fn execute_upgrade(&self) -> bool {
|
2016-12-09 20:40:24 +01:00
|
|
|
(|| -> Result<bool, String> {
|
2016-12-11 02:02:40 +01:00
|
|
|
let mut s = self.state.lock();
|
2016-12-10 23:58:39 +01:00
|
|
|
if let Some(r) = s.ready.take() {
|
2016-12-11 03:33:10 +01:00
|
|
|
let p = Self::update_file_name(&r.version);
|
|
|
|
let n = Self::updates_path("latest");
|
|
|
|
// TODO: creating then writing is a bit fragile. would be nice to make it atomic.
|
|
|
|
match fs::File::create(&n).and_then(|mut f| f.write_all(p.as_bytes())) {
|
2016-12-09 20:40:24 +01:00
|
|
|
Ok(_) => {
|
|
|
|
info!("Completed upgrade to {}", &r.version);
|
2016-12-10 23:58:39 +01:00
|
|
|
s.installed = Some(r);
|
2016-12-11 02:02:40 +01:00
|
|
|
if let Some(ref h) = *self.exit_handler.lock() {
|
2016-12-10 23:58:39 +01:00
|
|
|
(*h)();
|
|
|
|
}
|
2016-12-09 20:40:24 +01:00
|
|
|
Ok(true)
|
|
|
|
}
|
|
|
|
Err(e) => {
|
2016-12-10 23:58:39 +01:00
|
|
|
s.ready = Some(r);
|
2016-12-09 20:40:24 +01:00
|
|
|
Err(format!("Unable to create soft-link for update {:?}", e))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
warn!("Execute upgrade called when no upgrade ready.");
|
|
|
|
Ok(false)
|
|
|
|
}
|
|
|
|
})().unwrap_or_else(|e| { warn!("{}", e); false })
|
2016-11-24 17:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-11-30 10:16:18 +01:00
|
|
|
/// Our version info.
|
2016-11-25 15:43:49 +01:00
|
|
|
pub fn version_info(&self) -> &VersionInfo { &self.this }
|
2016-11-24 17:19:48 +01:00
|
|
|
|
2016-11-30 10:16:18 +01:00
|
|
|
/// Information gathered concerning the release.
|
2016-12-10 23:58:39 +01:00
|
|
|
pub fn info(&self) -> Option<OperationsInfo> { self.state.lock().latest.clone() }
|
|
|
|
|
|
|
|
/// Set a closure to call when we want to restart the client
|
2016-12-11 02:02:40 +01:00
|
|
|
pub fn set_exit_handler<F>(&self, f: F) where F: Fn() + 'static + Send {
|
|
|
|
*self.exit_handler.lock() = Some(Box::new(f));
|
2016-12-10 23:58:39 +01:00
|
|
|
}
|
2016-11-24 17:19:48 +01:00
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
fn collect_release_info(operations: &Operations, release_id: &H256) -> Result<ReleaseInfo, String> {
|
|
|
|
let (fork, track, semver, is_critical) = operations.release(CLIENT_ID, release_id)?;
|
|
|
|
let latest_binary = operations.checksum(CLIENT_ID, release_id, &platform())?;
|
2016-11-25 15:43:49 +01:00
|
|
|
Ok(ReleaseInfo {
|
|
|
|
version: VersionInfo::from_raw(semver, track, release_id.clone().into()),
|
|
|
|
is_critical: is_critical,
|
|
|
|
fork: fork as u64,
|
|
|
|
binary: if latest_binary.is_zero() { None } else { Some(latest_binary) },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn collect_latest(&self) -> Result<OperationsInfo, String> {
|
2016-12-11 02:02:40 +01:00
|
|
|
if let Some(ref operations) = *self.operations.lock() {
|
|
|
|
let this_fork = operations.release(CLIENT_ID, &self.this.hash.into()).ok()
|
|
|
|
.and_then(|(fork, track, _, _)| if track > 0 {Some(fork as u64)} else {None});
|
2016-12-10 23:58:39 +01:00
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
if self.this.track == ReleaseTrack::Unknown {
|
|
|
|
return Err(format!("Current executable ({}) is unreleased.", H160::from(self.this.hash)));
|
|
|
|
}
|
2016-11-20 13:18:56 +01:00
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
let latest_in_track = operations.latest_in_track(CLIENT_ID, self.this.track.into())?;
|
|
|
|
let in_track = Self::collect_release_info(operations, &latest_in_track)?;
|
|
|
|
let mut in_minor = Some(in_track.clone());
|
|
|
|
const PROOF: &'static str = "in_minor initialised and assigned with Some; loop breaks if None assigned; qed";
|
|
|
|
while in_minor.as_ref().expect(PROOF).version.track != self.this.track {
|
|
|
|
let track = match in_minor.as_ref().expect(PROOF).version.track {
|
|
|
|
ReleaseTrack::Beta => ReleaseTrack::Stable,
|
|
|
|
ReleaseTrack::Nightly => ReleaseTrack::Beta,
|
|
|
|
_ => { in_minor = None; break; }
|
|
|
|
};
|
|
|
|
in_minor = Some(Self::collect_release_info(operations, &operations.latest_in_track(CLIENT_ID, track.into())?)?);
|
|
|
|
}
|
2016-11-24 17:19:48 +01:00
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
Ok(OperationsInfo {
|
|
|
|
fork: operations.latest_fork()? as u64,
|
|
|
|
this_fork: this_fork,
|
|
|
|
track: in_track,
|
|
|
|
minor: in_minor,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
Err("Operations not available".into())
|
|
|
|
}
|
2016-11-22 10:24:22 +01:00
|
|
|
}
|
2016-11-20 13:18:56 +01:00
|
|
|
|
2016-12-11 03:33:10 +01:00
|
|
|
fn update_file_name(v: &VersionInfo) -> String {
|
|
|
|
format!("parity-{}.{}.{}-{:?}", v.version.major, v.version.minor, v.version.patch, v.hash)
|
2016-12-09 20:40:24 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 03:33:10 +01:00
|
|
|
fn updates_path(name: &str) -> PathBuf {
|
2016-12-09 20:40:24 +01:00
|
|
|
let mut dest = PathBuf::from(env::home_dir().unwrap().to_str().expect("env filesystem paths really should be valid; qed"));
|
|
|
|
dest.push(".parity-updates");
|
2016-12-11 03:33:10 +01:00
|
|
|
dest.push(name);
|
2016-12-09 20:40:24 +01:00
|
|
|
dest
|
|
|
|
}
|
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
fn fetch_done(&self, result: Result<PathBuf, fetch::Error>) {
|
2016-12-09 20:40:24 +01:00
|
|
|
(|| -> Result<(), String> {
|
2016-12-10 23:58:39 +01:00
|
|
|
let auto = {
|
2016-12-11 02:02:40 +01:00
|
|
|
let mut s = self.state.lock();
|
2016-12-10 23:58:39 +01:00
|
|
|
let fetched = s.fetching.take().unwrap();
|
|
|
|
let b = result.map_err(|e| format!("Unable to fetch update ({}): {:?}", fetched.version, e))?;
|
|
|
|
info!("Fetched latest version ({}) OK to {}", fetched.version, b.display());
|
2016-12-11 03:33:10 +01:00
|
|
|
let dest = Self::updates_path(&Self::update_file_name(&fetched.version));
|
2016-12-10 23:58:39 +01:00
|
|
|
fs::create_dir_all(dest.parent().expect("at least one thing pushed; qed")).map_err(|e| format!("Unable to create updates path: {:?}", e))?;
|
|
|
|
fs::copy(&b, &dest).map_err(|e| format!("Unable to copy update: {:?}", e))?;
|
|
|
|
info!("Copied file to {}", dest.display());
|
|
|
|
let auto = match self.update_policy.filter {
|
|
|
|
UpdateFilter::All => true,
|
|
|
|
UpdateFilter::Critical if fetched.is_critical /* TODO: or is on a bad fork */ => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
s.ready = Some(fetched);
|
|
|
|
auto
|
2016-12-09 20:40:24 +01:00
|
|
|
};
|
|
|
|
if auto {
|
2016-12-11 02:02:40 +01:00
|
|
|
// will lock self.state, so ensure it's outside of previous block.
|
2016-12-09 20:40:24 +01:00
|
|
|
self.execute_upgrade();
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
})().unwrap_or_else(|e| warn!("{}", e));
|
2016-11-25 19:29:13 +01:00
|
|
|
}
|
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
fn poll(&self) {
|
2016-11-22 10:24:22 +01:00
|
|
|
info!(target: "updater", "Current release is {}", self.this);
|
2016-11-25 15:43:49 +01:00
|
|
|
|
2016-12-11 02:02:40 +01:00
|
|
|
if self.operations.lock().is_none() {
|
|
|
|
if let Some(ops_addr) = self.client.upgrade().and_then(|c| c.registry_address("operations".into())) {
|
2016-12-10 23:58:39 +01:00
|
|
|
trace!(target: "client", "Found operations at {}", ops_addr);
|
|
|
|
let client = self.client.clone();
|
|
|
|
*self.operations.lock() = Some(Operations::new(ops_addr, move |a, d| client.upgrade().ok_or("No client!".into()).and_then(|c| c.call_contract(a, d))));
|
|
|
|
} else {
|
|
|
|
// No Operations contract - bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 15:43:49 +01:00
|
|
|
let current_number = self.client.upgrade().map_or(0, |c| c.block_number(BlockId::Latest).unwrap_or(0));
|
|
|
|
|
2016-12-10 23:58:39 +01:00
|
|
|
let latest = self.collect_latest().ok();
|
|
|
|
if let Some(ref latest) = latest {
|
2016-11-25 15:43:49 +01:00
|
|
|
info!(target: "updater", "Latest release in our track is v{} it is {}critical ({} binary is {})",
|
|
|
|
latest.track.version,
|
2016-11-30 10:16:18 +01:00
|
|
|
if latest.track.is_critical {""} else {"non-"},
|
2016-11-22 10:24:22 +01:00
|
|
|
platform(),
|
2016-11-25 15:43:49 +01:00
|
|
|
if let Some(ref b) = latest.track.binary {
|
2016-11-22 10:24:22 +01:00
|
|
|
format!("{}", b)
|
2016-12-09 19:02:42 +01:00
|
|
|
} else {
|
|
|
|
"unreleased".into()
|
|
|
|
}
|
2016-11-22 10:24:22 +01:00
|
|
|
);
|
2016-12-10 23:58:39 +01:00
|
|
|
let mut s = self.state.lock();
|
|
|
|
let running_latest = latest.track.version.hash == self.version_info().hash;
|
|
|
|
let already_have_latest = s.installed.as_ref().or(s.ready.as_ref()).map_or(false, |t| *t == latest.track);
|
|
|
|
if self.update_policy.enable_downloading && !running_latest && !already_have_latest {
|
2016-12-09 19:02:42 +01:00
|
|
|
if let Some(b) = latest.track.binary {
|
2016-12-11 02:02:40 +01:00
|
|
|
if s.fetching.is_none() {
|
2016-12-09 19:02:42 +01:00
|
|
|
info!("Attempting to get parity binary {}", b);
|
2016-12-10 23:58:39 +01:00
|
|
|
s.fetching = Some(latest.track.clone());
|
2016-12-11 02:02:40 +01:00
|
|
|
let weak_self = self.weak_self.lock().clone();
|
|
|
|
let f = move |r: Result<PathBuf, fetch::Error>| if let Some(this) = weak_self.upgrade() { this.fetch_done(r) };
|
2016-12-11 02:39:56 +01:00
|
|
|
self.fetcher.lock().as_ref().expect("Created on `new`; qed").fetch(b, Box::new(f)).ok();
|
2016-11-25 19:29:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 02:02:40 +01:00
|
|
|
info!(target: "updater", "Fork: this/current/latest/latest-known: {}/#{}/#{}/#{}", match latest.this_fork { Some(f) => format!("#{}", f), None => "unknown".into(), }, current_number, latest.track.fork, latest.fork);
|
2016-11-22 10:24:22 +01:00
|
|
|
}
|
2016-12-10 23:58:39 +01:00
|
|
|
(*self.state.lock()).latest = latest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ChainNotify for Updater {
|
2016-12-11 02:02:40 +01:00
|
|
|
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _duration: u64) {
|
2016-12-10 23:58:39 +01:00
|
|
|
// TODO: something like this
|
|
|
|
// if !self.client.upgrade().map_or(true, |c| c.is_major_syncing()) {
|
|
|
|
self.poll();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fetch::urlhint::ContractClient for Updater {
|
|
|
|
fn registrar(&self) -> Result<Address, String> {
|
|
|
|
self.client.upgrade().ok_or_else(|| "Client not available".to_owned())?
|
|
|
|
.registrar_address()
|
|
|
|
.ok_or_else(|| "Registrar not available".into())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call(&self, address: Address, data: Bytes) -> Result<Bytes, String> {
|
|
|
|
self.client.upgrade().ok_or_else(|| "Client not available".to_owned())?
|
|
|
|
.call_contract(address, data)
|
2016-11-18 12:14:52 +01:00
|
|
|
}
|
|
|
|
}
|