openethereum/rpc/src/v1/impls/light/parity_set.rs

153 lines
4.2 KiB
Rust
Raw Normal View History

// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
2017-02-17 21:43:15 +01:00
// Parity Ethereum is free software: you can redistribute it and/or modify
2017-02-17 21:43:15 +01:00
// 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,
2017-02-17 21:43:15 +01:00
// 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 <http://www.gnu.org/licenses/>.
2017-02-17 21:43:15 +01:00
//! Parity-specific rpc interface for operations altering the settings.
//! Implementation for light client.
use std::io;
2017-02-17 22:21:43 +01:00
use std::sync::Arc;
2017-02-17 21:43:15 +01:00
use ethereum_types::{H160, H256, U256};
use fetch::{self, Fetch};
2017-08-31 11:35:41 +02:00
use hash::keccak_buffer;
use light::client::LightChainClient;
use sync::ManageNetwork;
2017-02-17 21:43:15 +01:00
2017-11-14 11:38:17 +01:00
use jsonrpc_core::{Result, BoxFuture};
use jsonrpc_core::futures::Future;
2017-02-17 21:43:15 +01:00
use v1::helpers::errors;
use v1::traits::ParitySet;
use v1::types::{Bytes, ReleaseInfo, Transaction};
2017-02-17 21:43:15 +01:00
/// Parity-specific rpc interface for operations altering the settings.
pub struct ParitySetClient<F> {
client: Arc<LightChainClient>,
2017-02-17 21:43:15 +01:00
net: Arc<ManageNetwork>,
fetch: F,
}
impl<F: Fetch> ParitySetClient<F> {
/// Creates new `ParitySetClient` with given `Fetch`.
pub fn new(client: Arc<LightChainClient>, net: Arc<ManageNetwork>, fetch: F) -> Self {
2017-02-17 21:43:15 +01:00
ParitySetClient {
client,
net,
fetch,
2017-02-17 21:43:15 +01:00
}
}
}
impl<F: Fetch> ParitySet for ParitySetClient<F> {
2017-11-14 11:38:17 +01:00
fn set_min_gas_price(&self, _gas_price: U256) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn set_gas_floor_target(&self, _target: U256) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn set_gas_ceil_target(&self, _target: U256) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn set_extra_data(&self, _extra_data: Bytes) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn set_author(&self, _author: H160) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
fn set_engine_signer_secret(&self, _secret: H256) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn set_transactions_limit(&self, _limit: usize) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn set_tx_gas_limit(&self, _limit: U256) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn add_reserved_peer(&self, peer: String) -> Result<bool> {
2017-02-17 21:43:15 +01:00
match self.net.add_reserved_peer(peer) {
Ok(()) => Ok(true),
Err(e) => Err(errors::invalid_params("Peer address", e)),
}
}
2017-11-14 11:38:17 +01:00
fn remove_reserved_peer(&self, peer: String) -> Result<bool> {
2017-02-17 21:43:15 +01:00
match self.net.remove_reserved_peer(peer) {
Ok(()) => Ok(true),
Err(e) => Err(errors::invalid_params("Peer address", e)),
}
}
2017-11-14 11:38:17 +01:00
fn drop_non_reserved_peers(&self) -> Result<bool> {
2017-02-17 21:43:15 +01:00
self.net.deny_unreserved_peers();
Ok(true)
}
2017-11-14 11:38:17 +01:00
fn accept_non_reserved_peers(&self) -> Result<bool> {
2017-02-17 21:43:15 +01:00
self.net.accept_unreserved_peers();
Ok(true)
}
2017-11-14 11:38:17 +01:00
fn start_network(&self) -> Result<bool> {
2017-02-17 21:43:15 +01:00
self.net.start_network();
Ok(true)
}
2017-11-14 11:38:17 +01:00
fn stop_network(&self) -> Result<bool> {
2017-02-17 21:43:15 +01:00
self.net.stop_network();
Ok(true)
}
2017-11-14 11:38:17 +01:00
fn set_mode(&self, _mode: String) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
fn set_spec_name(&self, spec_name: String) -> Result<bool> {
self.client.set_spec_name(spec_name).map(|_| true).map_err(|()| errors::cannot_restart())
}
2017-11-14 11:38:17 +01:00
fn hash_content(&self, url: String) -> BoxFuture<H256> {
Private transactions integration pr (#6422) * Private transaction message added * Empty line removed * Private transactions logic removed from client into the separate module * Fixed compilation after merge with head * Signed private transaction message added as well * Comments after the review fixed * Private tx execution * Test update * Renamed some methods * Fixed some tests * Reverted submodules * Fixed build * Private transaction message added * Empty line removed * Private transactions logic removed from client into the separate module * Fixed compilation after merge with head * Signed private transaction message added as well * Comments after the review fixed * Encrypted private transaction message and signed reply added * Private tx execution * Test update * Main scenario completed * Merged with the latest head * Private transactions API * Comments after review fixed * Parameters for private transactions added to parity arguments * New files added * New API methods added * Do not process packets from unconfirmed peers * Merge with ptm_ss branch * Encryption and permissioning with key server added * Fixed compilation after merge * Version of Parity protocol incremented in order to support private transactions * Doc strings for constants added * Proper format for doc string added * fixed some encryptor.rs grumbles * Private transactions functionality moved to the separate crate * Refactoring in order to remove late initialisation * Tests fixed after moving to the separate crate * Fetch method removed * Sync test helpers refactored * Interaction with encryptor refactored * Contract address retrieving via substate removed * Sensible gas limit for private transactions implemented * New private contract with nonces added * Parsing of the response from key server fixed * Build fixed after the merge, native contracts removed * Crate renamed * Tests moved to the separate directory * Handling of errors reworked in order to use error chain * Encodable macro added, new constructor replaced with default * Native ethabi usage removed * Couple conversions optimized * Interactions with client reworked * Errors omitting removed * Fix after merge * Fix after the merge * private transactions improvements in progress * private_transactions -> ethcore/private-tx * making private transactions more idiomatic * private-tx encryptor uses shared FetchClient and is more idiomatic * removed redundant tests, moved integration tests to tests/ dir * fixed failing service test * reenable add_notify on private tx provider * removed private_tx tests from sync module * removed commented out code * Use plain password instead of unlocking account manager * remove dead code * Link to the contract changed * Transaction signature chain replay protection module created * Redundant type conversion removed * Contract address returned by private provider * Test fixed * Addressing grumbles in PrivateTransactions (#8249) * Tiny fixes part 1. * A bunch of additional comments and todos. * Fix ethsync tests. * resolved merge conflicts * final private tx pr (#8318) * added cli option that enables private transactions * fixed failing test * fixed failing test * fixed failing test * fixed failing test
2018-04-09 16:14:33 +02:00
let future = self.fetch.get(&url, Default::default()).then(move |result| {
2017-02-17 21:43:15 +01:00
result
.map_err(errors::fetch)
.and_then(move |response| {
let mut reader = io::BufReader::new(fetch::BodyReader::new(response));
keccak_buffer(&mut reader).map_err(errors::fetch)
2017-02-17 21:43:15 +01:00
})
.map(Into::into)
});
Box::new(future)
2017-02-17 21:43:15 +01:00
}
2017-11-14 11:38:17 +01:00
fn upgrade_ready(&self) -> Result<Option<ReleaseInfo>> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-11-14 11:38:17 +01:00
fn execute_upgrade(&self) -> Result<bool> {
2017-02-17 21:43:15 +01:00
Err(errors::light_unimplemented(None))
}
2017-03-19 08:46:51 +01:00
2017-11-14 11:38:17 +01:00
fn remove_transaction(&self, _hash: H256) -> Result<Option<Transaction>> {
2017-03-19 08:46:51 +01:00
Err(errors::light_unimplemented(None))
}
2017-02-17 21:43:15 +01:00
}