diff --git a/Cargo.lock b/Cargo.lock
index 8d60c2289..f7ab1ad9e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1477,16 +1477,10 @@ name = "ethcore-secretstore"
version = "1.0.0"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "client-traits 0.1.0",
- "common-types 0.1.0",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi 9.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-contract 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-derive 9.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "ethcore 1.12.0",
- "ethcore-accounts 0.1.0",
- "ethcore-call-contract 0.1.0",
- "ethcore-sync 1.12.0",
"ethereum-types 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethkey 0.4.0",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1502,7 +1496,6 @@ dependencies = [
"parity-runtime 0.1.0",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "registrar 0.0.1",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3085,9 +3078,11 @@ dependencies = [
"dir 0.1.2",
"docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"engine 0.1.0",
+ "ethabi 9.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethcore 1.12.0",
"ethcore-accounts 0.1.0",
"ethcore-blockchain 0.1.0",
+ "ethcore-call-contract 0.1.0",
"ethcore-db 0.1.0",
"ethcore-io 1.12.0",
"ethcore-light 1.12.0",
diff --git a/Cargo.toml b/Cargo.toml
index 53ffb641e..9d667e9ef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,9 +18,11 @@ ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
dir = { path = "util/dir" }
docopt = "1.0"
engine = { path = "ethcore/engine" }
+ethabi = { version = "9.0.1", optional = true }
ethcore = { path = "ethcore", features = ["parity"] }
ethcore-accounts = { path = "accounts", optional = true }
ethcore-blockchain = { path = "ethcore/blockchain" }
+ethcore-call-contract = { path = "ethcore/call-contract", optional = true }
ethcore-db = { path = "ethcore/db" }
ethcore-io = { path = "util/io" }
ethcore-light = { path = "ethcore/light" }
@@ -97,7 +99,7 @@ test-heavy = ["ethcore/test-heavy"]
evm-debug = ["ethcore/evm-debug"]
evm-debug-tests = ["ethcore/evm-debug-tests"]
slow-blocks = ["ethcore/slow-blocks"]
-secretstore = ["ethcore-secretstore", "ethcore-secretstore/accounts"]
+secretstore = ["ethcore-secretstore", "accounts", "ethabi", "ethcore-call-contract"]
final = ["parity-version/final"]
deadlock_detection = ["parking_lot/deadlock_detection"]
# to create a memory profile (requires nightly rust), use e.g.
diff --git a/parity/lib.rs b/parity/lib.rs
index 0af8ce419..c814200bb 100644
--- a/parity/lib.rs
+++ b/parity/lib.rs
@@ -86,6 +86,12 @@ extern crate ethcore_accounts as accounts;
#[cfg(feature = "secretstore")]
extern crate ethcore_secretstore;
+#[cfg(feature = "secretstore")]
+extern crate ethabi;
+
+#[cfg(feature = "secretstore")]
+extern crate ethcore_call_contract as call_contract;
+
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
diff --git a/parity/secretstore/blockchain.rs b/parity/secretstore/blockchain.rs
new file mode 100644
index 000000000..6c0587538
--- /dev/null
+++ b/parity/secretstore/blockchain.rs
@@ -0,0 +1,246 @@
+// Copyright 2015-2019 Parity Technologies (UK) Ltd.
+// This file is part of Parity Ethereum.
+
+// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see .
+
+//! SecretStoreChain implementation with information about blockchain, retrieved from the client
+
+use std::sync::{Arc, Weak};
+use ethereum_types::{H256, Address};
+use parking_lot::RwLock;
+use types::{
+ ids::BlockId as EthcoreBlockId,
+ transaction::{Transaction, SignedTransaction, Action},
+ chain_notify::NewBlocks,
+ tree_route::TreeRoute,
+ filter::Filter as BlockchainFilter,
+ log_entry::LocalizedLogEntry,
+};
+use ethcore::client::Client;
+use bytes::Bytes;
+use ethabi::RawLog;
+use client_traits::BlockChainClient;
+use call_contract::CallContract;
+use client_traits::{ChainInfo, Nonce, ChainNotify};
+use ethcore::miner::{Miner, MinerService};
+use parity_crypto::publickey::Error as EthKeyError;
+use sync::SyncProvider;
+use registrar::RegistrarClient;
+use ethcore_secretstore::{BlockId, BlockNumber, SecretStoreChain, NewBlocksNotify, SigningKeyPair, ContractAddress, Filter};
+
+// TODO: Instead of a constant, make this based on consensus finality.
+/// Number of confirmations required before request can be processed.
+const REQUEST_CONFIRMATIONS_REQUIRED: u64 = 3;
+
+fn into_ethcore_block_id(id: BlockId) -> EthcoreBlockId {
+ match id {
+ BlockId::Hash(hash) => EthcoreBlockId::Hash(hash),
+ BlockId::Number(number) => EthcoreBlockId::Number(number),
+ BlockId::Earliest => EthcoreBlockId::Earliest,
+ BlockId::Latest => EthcoreBlockId::Latest,
+ }
+}
+
+/// SecretStore blockchain implementation (client's wrapper)
+/// This implementation is trusted, when underlying client is synced and chain's security level is full
+/// This trust is guaranteed by return result in get_trusted method (if it's not trusted, None is returned)
+pub struct TrustedClient {
+ /// This key server node key pair.
+ self_key_pair: Arc,
+ /// Blockchain client.
+ client: Weak,
+ /// Sync provider.
+ sync: Weak,
+ /// Miner service.
+ miner: Weak,
+ /// Chain new blocks listeners
+ listeners: RwLock>>,
+}
+
+impl TrustedClient {
+ /// Create new trusted client.
+ pub fn new(self_key_pair: Arc, client: Arc, sync: Arc, miner: Arc) -> Arc {
+ let trusted_client = Arc::new(TrustedClient {
+ self_key_pair,
+ client: Arc::downgrade(&client),
+ sync: Arc::downgrade(&sync),
+ miner: Arc::downgrade(&miner),
+ listeners: RwLock::default(),
+ });
+ client.add_notify(trusted_client.clone());
+ trusted_client
+ }
+
+ fn notify_listeners(&self, new_enacted_len: usize) {
+ for listener_pointer in self.listeners.read().iter() {
+ if let Some(listener) = listener_pointer.upgrade() {
+ listener.new_blocks(new_enacted_len);
+ }
+ }
+ }
+
+ /// Get 'trusted' `Client` reference only if it is synchronized && trusted.
+ fn get_trusted(&self) -> Option> {
+ self.client.upgrade()
+ .and_then(|client| self.sync.upgrade().map(|sync| (client, sync)))
+ .and_then(|(client, sync)| {
+ let is_synced = !sync.is_major_syncing();
+ let is_trusted = client.chain_info().security_level().is_full();
+ match is_synced && is_trusted {
+ true => Some(client),
+ false => None,
+ }
+ })
+ }
+
+ fn tree_route(&self, from: &H256, to: &H256) -> Option {
+ if let Some(client) = self.get_trusted() {
+ client.tree_route(from, to)
+ } else {
+ None
+ }
+ }
+
+ fn logs(&self, filter: BlockchainFilter) -> Option> {
+ if let Some(client) = self.get_trusted() {
+ client.logs(filter).ok()
+ } else {
+ None
+ }
+ }
+
+}
+
+impl SecretStoreChain for TrustedClient {
+ fn add_listener(&self, target: Arc) {
+ self.listeners.write().push(Arc::downgrade(&target));
+ }
+
+ fn is_trusted(&self) -> bool {
+ self.get_trusted().is_some()
+ }
+
+ fn transact_contract(&self, contract: Address, tx_data: Bytes) -> Result<(), EthKeyError> {
+ let client = self.client.upgrade().ok_or_else(|| EthKeyError::Custom("cannot submit tx when client is offline".into()))?;
+ let miner = self.miner.upgrade().ok_or_else(|| EthKeyError::Custom("cannot submit tx when miner is offline".into()))?;
+ let engine = client.engine();
+ let transaction = Transaction {
+ nonce: client.latest_nonce(&self.self_key_pair.address()),
+ action: Action::Call(contract),
+ gas: miner.authoring_params().gas_range_target.0,
+ gas_price: miner.sensible_gas_price(),
+ value: Default::default(),
+ data: tx_data,
+ };
+ let chain_id = engine.signing_chain_id(&client.latest_env_info());
+ let signature = self.self_key_pair.sign(&transaction.hash(chain_id))?;
+ let signed = SignedTransaction::new(transaction.with_signature(signature, chain_id))?;
+ miner.import_own_transaction(&*client, signed.into())
+ .map_err(|e| EthKeyError::Custom(format!("failed to import tx: {}", e)))
+ }
+
+ fn read_contract_address(
+ &self,
+ registry_name: &str,
+ address: &ContractAddress
+ ) -> Option {
+ match *address {
+ ContractAddress::Address(ref address) => Some(address.clone()),
+ ContractAddress::Registry => self.get_trusted().and_then(|client|
+ self.get_confirmed_block_hash()
+ .and_then(|block| {
+ client.get_address(registry_name, EthcoreBlockId::Hash(block))
+ .unwrap_or(None)
+ })
+ ),
+ }
+ }
+
+ fn call_contract(&self, block_id: BlockId, contract_address: Address, data: Bytes) -> Result {
+ if let Some(client) = self.get_trusted() {
+ client.call_contract(into_ethcore_block_id(block_id), contract_address, data)
+ } else {
+ Err("Calling ACL contract without trusted blockchain client".into())
+ }
+ }
+
+ fn block_hash(&self, id: BlockId) -> Option {
+ if let Some(client) = self.get_trusted() {
+ client.block_hash(into_ethcore_block_id(id))
+ } else {
+ None
+ }
+ }
+
+ fn block_number(&self, id: BlockId) -> Option {
+ if let Some(client) = self.get_trusted() {
+ client.block_number(into_ethcore_block_id(id))
+ } else {
+ None
+ }
+ }
+
+ fn retrieve_last_logs(&self, filter: Filter) -> Option> {
+ let confirmed_block = match self.get_confirmed_block_hash() {
+ Some(confirmed_block) => confirmed_block,
+ None => return None, // no block with enough confirmations
+ };
+
+ let from_block = self.block_hash(filter.from_block).unwrap_or_else(|| confirmed_block);
+ let first_block = match self.tree_route(&from_block, &confirmed_block) {
+ // if we have a route from last_log_block to confirmed_block => search for logs on this route
+ //
+ // potentially this could lead us to reading same logs twice when reorganizing to the fork, which
+ // already has been canonical previosuly
+ // the worst thing that can happen in this case is spending some time reading unneeded data from SS db
+ Some(ref route) if route.index < route.blocks.len() => route.blocks[route.index],
+ // else we care only about confirmed block
+ _ => confirmed_block.clone(),
+ };
+
+ self.logs(BlockchainFilter {
+ from_block: EthcoreBlockId::Hash(first_block),
+ to_block: EthcoreBlockId::Hash(confirmed_block),
+ address: filter.address,
+ topics: filter.topics,
+ limit: None,
+ })
+ .map(|blockchain_logs| {
+ blockchain_logs
+ .into_iter()
+ .map(|log| {
+ let raw_log: RawLog = (log.entry.topics.into_iter().map(|t| t.0.into()).collect(), log.entry.data).into();
+ raw_log
+ })
+ .collect::>()
+ })
+ }
+
+ fn get_confirmed_block_hash(&self) -> Option {
+ self.block_number(BlockId::Latest)
+ .map(|b| b.saturating_sub(REQUEST_CONFIRMATIONS_REQUIRED))
+ .and_then(|b| self.block_hash(BlockId::Number(b)))
+ }
+}
+
+impl ChainNotify for TrustedClient {
+ fn new_blocks(&self, new_blocks: NewBlocks) {
+ if new_blocks.has_more_blocks_to_import { return }
+ if !new_blocks.route.enacted().is_empty() || !new_blocks.route.retracted().is_empty() {
+ let enacted_len = new_blocks.route.enacted().len();
+ self.notify_listeners(enacted_len);
+ }
+ }
+}
+
diff --git a/secret-store/src/helpers.rs b/parity/secretstore/mod.rs
similarity index 55%
rename from secret-store/src/helpers.rs
rename to parity/secretstore/mod.rs
index cdb235ac9..2b16965fa 100644
--- a/secret-store/src/helpers.rs
+++ b/parity/secretstore/mod.rs
@@ -14,18 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see .
-use ethcore::client::Client;
-use client_traits::BlockChainClient;
-use common_types::ids::BlockId;
-use ethereum_types::H256;
+//! Secret store related components.
-// TODO: Instead of a constant, make this based on consensus finality.
-/// Number of confirmations required before request can be processed.
-pub const REQUEST_CONFIRMATIONS_REQUIRED: u64 = 3;
+mod server;
-/// Get hash of the last block with at least n confirmations.
-pub fn get_confirmed_block_hash(client: &Client, confirmations: u64) -> Option {
- client.block_number(BlockId::Latest)
- .map(|b| b.saturating_sub(confirmations))
- .and_then(|b| client.block_hash(BlockId::Number(b)))
-}
+#[cfg(feature = "secretstore")]
+mod blockchain;
+
+#[cfg(all(feature = "accounts", feature = "secretstore"))]
+mod nodekeypair;
+
+pub use self::server::{Configuration, NodeSecretKey, ContractAddress, Dependencies, start};
+#[cfg(feature = "secretstore")]
+use self::blockchain::TrustedClient;
+#[cfg(all(feature = "accounts", feature = "secretstore"))]
+use self::nodekeypair::KeyStoreNodeKeyPair;
\ No newline at end of file
diff --git a/parity/secretstore/nodekeypair.rs b/parity/secretstore/nodekeypair.rs
new file mode 100644
index 000000000..67ad3d1ec
--- /dev/null
+++ b/parity/secretstore/nodekeypair.rs
@@ -0,0 +1,59 @@
+// Copyright 2015-2019 Parity Technologies (UK) Ltd.
+// This file is part of Parity Ethereum.
+
+// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see .
+
+//! Key pair with signing ability
+
+use std::sync::Arc;
+use accounts::AccountProvider;
+use ethkey::Password;
+use parity_crypto::publickey::public_to_address;
+use ethereum_types::{H256, Address, Public};
+use parity_crypto::publickey::{Signature, Error as EthKeyError};
+use ethcore_secretstore::SigningKeyPair;
+
+pub struct KeyStoreNodeKeyPair {
+ account_provider: Arc,
+ address: Address,
+ public: Public,
+ password: Password,
+}
+
+impl KeyStoreNodeKeyPair {
+ pub fn new(account_provider: Arc, address: Address, password: Password) -> Result {
+ let public = account_provider.account_public(address.clone(), &password).map_err(|e| EthKeyError::Custom(format!("{}", e)))?;
+ Ok(KeyStoreNodeKeyPair {
+ account_provider,
+ address,
+ public,
+ password,
+ })
+ }
+}
+
+impl SigningKeyPair for KeyStoreNodeKeyPair {
+ fn public(&self) -> &Public {
+ &self.public
+ }
+
+ fn address(&self) -> Address {
+ public_to_address(&self.public)
+ }
+
+ fn sign(&self, data: &H256) -> Result {
+ self.account_provider.sign(self.address.clone(), Some(self.password.clone()), data.clone())
+ .map_err(|e| EthKeyError::Custom(format!("{}", e)))
+ }
+}
diff --git a/parity/secretstore.rs b/parity/secretstore/server.rs
similarity index 93%
rename from parity/secretstore.rs
rename to parity/secretstore/server.rs
index 25af61e87..033f290e7 100644
--- a/parity/secretstore.rs
+++ b/parity/secretstore/server.rs
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see .
+//! Secret store server's launcher, contains required configuration parameters and launch method
+
use std::collections::BTreeMap;
use std::sync::Arc;
use account_utils::AccountProvider;
@@ -125,6 +127,9 @@ mod server {
use parity_crypto::publickey::KeyPair;
use ansi_term::Colour::{Red, White};
use super::{Configuration, Dependencies, NodeSecretKey, ContractAddress, Executor};
+ use super::super::TrustedClient;
+ #[cfg(feature = "accounts")]
+ use super::super::KeyStoreNodeKeyPair;
fn into_service_contract_address(address: ContractAddress) -> ethcore_secretstore::ContractAddress {
match address {
@@ -141,7 +146,7 @@ mod server {
impl KeyServer {
/// Create new key server
pub fn new(mut conf: Configuration, deps: Dependencies, executor: Executor) -> Result {
- let self_secret: Arc = match conf.self_secret.take() {
+ let self_secret: Arc = match conf.self_secret.take() {
Some(NodeSecretKey::Plain(secret)) => Arc::new(ethcore_secretstore::PlainNodeKeyPair::new(
KeyPair::from_secret(secret).map_err(|e| format!("invalid secret: {}", e))?)),
#[cfg(feature = "accounts")]
@@ -160,7 +165,7 @@ mod server {
let password = deps.accounts_passwords.iter()
.find(|p| deps.account_provider.sign(account.clone(), Some((*p).clone()), Default::default()).is_ok())
.ok_or_else(|| format!("No valid password for the secret store node account {}", account))?;
- Arc::new(ethcore_secretstore::KeyStoreNodeKeyPair::new(deps.account_provider, account, password.clone())
+ Arc::new(KeyStoreNodeKeyPair::new(deps.account_provider, account, password.clone())
.map_err(|e| format!("{}", e))?)
},
None => return Err("self secret is required when using secretstore".into()),
@@ -203,7 +208,8 @@ mod server {
cconf.cluster_config.nodes.insert(self_secret.public().clone(), cconf.cluster_config.listener_address.clone());
let db = ethcore_secretstore::open_secretstore_db(&conf.data_path)?;
- let key_server = ethcore_secretstore::start(deps.client, deps.sync, deps.miner, self_secret, cconf, db, executor)
+ let trusted_client = TrustedClient::new(self_secret.clone(), deps.client, deps.sync, deps.miner);
+ let key_server = ethcore_secretstore::start(trusted_client, self_secret, cconf, db, executor)
.map_err(|e| format!("Error starting KeyServer {}: {}", key_server_name, e))?;
Ok(KeyServer {
diff --git a/secret-store/Cargo.toml b/secret-store/Cargo.toml
index 11cad8ba2..609e5ff62 100644
--- a/secret-store/Cargo.toml
+++ b/secret-store/Cargo.toml
@@ -7,15 +7,9 @@ authors = ["Parity Technologies "]
[dependencies]
byteorder = "1.0"
-client-traits = { path = "../ethcore/client-traits" }
-common-types = { path = "../ethcore/types" }
ethabi = "9.0.1"
ethabi-contract = "9.0.0"
ethabi-derive = "9.0.1"
-ethcore = { path = "../ethcore" }
-ethcore-accounts = { path = "../accounts", optional = true}
-ethcore-call-contract = { path = "../ethcore/call-contract" }
-ethcore-sync = { path = "../ethcore/sync" }
ethereum-types = "0.8.0"
ethkey = { path = "../accounts/ethkey", optional = true }
futures = "0.1"
@@ -30,7 +24,6 @@ parity-crypto = { version = "0.4.2", features = ["publickey"] }
parity-runtime = { path = "../util/runtime" }
parking_lot = "0.9"
percent-encoding = "2.1.0"
-registrar = { path = "../util/registrar" }
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
@@ -44,10 +37,5 @@ jsonrpc-server-utils = "14.0.3"
[dev-dependencies]
env_logger = "0.5"
-ethkey = { path = "../accounts/ethkey" }
-ethcore = { path = "../ethcore", features = ["test-helpers"] }
tempdir = "0.3"
kvdb-rocksdb = "0.3.0"
-
-[features]
-accounts = ["ethcore-accounts", "ethkey"]
diff --git a/secret-store/src/acl_storage.rs b/secret-store/src/acl_storage.rs
index d3f8bddde..0da50e310 100644
--- a/secret-store/src/acl_storage.rs
+++ b/secret-store/src/acl_storage.rs
@@ -16,17 +16,11 @@
use std::sync::Arc;
use std::collections::{HashMap, HashSet};
-use common_types::{
- chain_notify::NewBlocks,
- ids::BlockId
-};
use parking_lot::{Mutex, RwLock};
-use call_contract::CallContract;
-use client_traits::ChainNotify;
use ethereum_types::Address;
use ethabi::FunctionOutputDecoder;
-use trusted_client::TrustedClient;
-use types::{Error, ServerKeyId, ContractAddress};
+use blockchain::{SecretStoreChain, NewBlocksNotify, ContractAddress, BlockId};
+use types::{Error, ServerKeyId};
use_contract!(acl_storage, "res/acl_storage.json");
@@ -47,7 +41,7 @@ pub struct OnChainAclStorage {
/// Cached on-chain ACL storage contract.
struct CachedContract {
/// Blockchain client.
- client: TrustedClient,
+ client: Arc,
/// Contract address source.
address_source: ContractAddress,
/// Current contract address.
@@ -61,14 +55,11 @@ pub struct DummyAclStorage {
}
impl OnChainAclStorage {
- pub fn new(trusted_client: TrustedClient, address_source: ContractAddress) -> Result, Error> {
- let client = trusted_client.get_untrusted();
+ pub fn new(trusted_client: Arc, address_source: ContractAddress) -> Result, Error> {
let acl_storage = Arc::new(OnChainAclStorage {
- contract: Mutex::new(CachedContract::new(trusted_client, address_source)),
+ contract: Mutex::new(CachedContract::new(trusted_client.clone(), address_source)),
});
- client
- .ok_or_else(|| Error::Internal("Constructing OnChainAclStorage without active Client".into()))?
- .add_notify(acl_storage.clone());
+ trusted_client.add_listener(acl_storage.clone());
Ok(acl_storage)
}
}
@@ -79,17 +70,14 @@ impl AclStorage for OnChainAclStorage {
}
}
-impl ChainNotify for OnChainAclStorage {
- fn new_blocks(&self, new_blocks: NewBlocks) {
- if new_blocks.has_more_blocks_to_import { return }
- if !new_blocks.route.enacted().is_empty() || !new_blocks.route.retracted().is_empty() {
- self.contract.lock().update_contract_address()
- }
+impl NewBlocksNotify for OnChainAclStorage {
+ fn new_blocks(&self, _new_enacted_len: usize) {
+ self.contract.lock().update_contract_address()
}
}
impl CachedContract {
- pub fn new(client: TrustedClient, address_source: ContractAddress) -> Self {
+ pub fn new(client: Arc, address_source: ContractAddress) -> Self {
let mut contract = CachedContract {
client,
address_source,
@@ -113,12 +101,12 @@ impl CachedContract {
}
pub fn check(&mut self, requester: Address, document: &ServerKeyId) -> Result {
- if let Some(client) = self.client.get() {
+ if self.client.is_trusted() {
// call contract to check accesss
match self.contract_address {
Some(contract_address) => {
let (encoded, decoder) = acl_storage::functions::check_permissions::call(requester, document.clone());
- let d = client.call_contract(BlockId::Latest, contract_address, encoded)
+ let d = self.client.call_contract(BlockId::Latest, contract_address, encoded)
.map_err(|e| Error::Internal(format!("ACL checker call error: {}", e.to_string())))?;
decoder.decode(&d)
.map_err(|e| Error::Internal(format!("ACL checker call error: {}", e.to_string())))
diff --git a/secret-store/src/blockchain.rs b/secret-store/src/blockchain.rs
new file mode 100644
index 000000000..d2ad28d7e
--- /dev/null
+++ b/secret-store/src/blockchain.rs
@@ -0,0 +1,119 @@
+// Copyright 2015-2019 Parity Technologies (UK) Ltd.
+// This file is part of Parity Ethereum.
+
+// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see .
+
+use std::sync::Arc;
+use bytes::Bytes;
+use ethereum_types::{H256, Address, Public};
+use ethabi::RawLog;
+use crypto::publickey::{Signature, Error as EthKeyError};
+
+/// Type for block number.
+/// Duplicated from ethcore types
+pub type BlockNumber = u64;
+
+/// Uniquely identifies block.
+/// Duplicated from ethcore types
+#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)]
+pub enum BlockId {
+ /// Block's sha3.
+ /// Querying by hash is always faster.
+ Hash(H256),
+ /// Block number within canon blockchain.
+ Number(BlockNumber),
+ /// Earliest block (genesis).
+ Earliest,
+ /// Latest mined block.
+ Latest,
+}
+
+/// Contract address.
+#[derive(Debug, Clone)]
+pub enum ContractAddress {
+ /// Address is read from registry.
+ Registry,
+ /// Address is specified.
+ Address(ethereum_types::Address),
+}
+
+/// Key pair with signing ability.
+pub trait SigningKeyPair: Send + Sync {
+ /// Public portion of key.
+ fn public(&self) -> &Public;
+ /// Address of key owner.
+ fn address(&self) -> Address;
+ /// Sign data with the key.
+ fn sign(&self, data: &H256) -> Result;
+}
+
+/// Wrapps client ChainNotify in order to send signal about new blocks
+pub trait NewBlocksNotify: Send + Sync {
+ /// Fires when chain has new blocks.
+ /// Sends this signal only, if contracts' update required
+ fn new_blocks(&self, _new_enacted_len: usize) {
+ // does nothing by default
+ }
+}
+
+/// Blockchain logs Filter.
+#[derive(Debug, PartialEq)]
+pub struct Filter {
+ /// Blockchain will be searched from this block.
+ pub from_block: BlockId,
+
+ /// Search addresses.
+ ///
+ /// If None, match all.
+ /// If specified, log must be produced by one of these addresses.
+ pub address: Option>,
+
+ /// Search topics.
+ ///
+ /// If None, match all.
+ /// If specified, log must contain one of these topics.
+ pub topics: Vec