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
This commit is contained in:
committed by
Marek Kotewicz
parent
c039ab79b5
commit
e6f75bccfe
@@ -44,6 +44,7 @@ ethcore-io = { path = "../util/io" }
|
||||
ethcore-light = { path = "../ethcore/light" }
|
||||
ethcore-logger = { path = "../logger" }
|
||||
ethcore-miner = { path = "../miner" }
|
||||
ethcore-private-tx = { path = "../ethcore/private-tx" }
|
||||
ethcore-transaction = { path = "../ethcore/transaction" }
|
||||
ethereum-types = "0.3"
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ extern crate rlp;
|
||||
extern crate stats;
|
||||
extern crate keccak_hash as hash;
|
||||
extern crate hardware_wallet;
|
||||
extern crate ethcore_private_tx;
|
||||
extern crate patricia_trie as trie;
|
||||
|
||||
#[macro_use]
|
||||
|
||||
@@ -23,6 +23,7 @@ use ethcore::error::{Error as EthcoreError, CallError};
|
||||
use jsonrpc_core::{futures, Error, ErrorCode, Value};
|
||||
use rlp::DecoderError;
|
||||
use transaction::Error as TransactionError;
|
||||
use ethcore_private_tx::Error as PrivateTransactionError;
|
||||
|
||||
mod codes {
|
||||
// NOTE [ToDr] Codes from [-32099, -32000]
|
||||
@@ -39,6 +40,7 @@ mod codes {
|
||||
pub const ACCOUNT_LOCKED: i64 = -32020;
|
||||
pub const PASSWORD_INVALID: i64 = -32021;
|
||||
pub const ACCOUNT_ERROR: i64 = -32023;
|
||||
pub const PRIVATE_ERROR: i64 = -32024;
|
||||
pub const REQUEST_REJECTED: i64 = -32040;
|
||||
pub const REQUEST_REJECTED_LIMIT: i64 = -32041;
|
||||
pub const REQUEST_NOT_FOUND: i64 = -32042;
|
||||
@@ -288,6 +290,22 @@ pub fn password(error: AccountError) -> Error {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn private_message(error: PrivateTransactionError) -> Error {
|
||||
Error {
|
||||
code: ErrorCode::ServerError(codes::PRIVATE_ERROR),
|
||||
message: "Private transactions call failed.".into(),
|
||||
data: Some(Value::String(format!("{:?}", error))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn private_message_block_id_not_supported() -> Error {
|
||||
Error {
|
||||
code: ErrorCode::ServerError(codes::PRIVATE_ERROR),
|
||||
message: "Pending block id not supported.".into(),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transaction_message(error: TransactionError) -> String {
|
||||
use self::TransactionError::*;
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ impl<F: Fetch> ParitySet for ParitySetClient<F> {
|
||||
}
|
||||
|
||||
fn hash_content(&self, url: String) -> BoxFuture<H256> {
|
||||
let future = self.fetch.fetch(&url, Default::default()).then(move |result| {
|
||||
let future = self.fetch.get(&url, Default::default()).then(move |result| {
|
||||
result
|
||||
.map_err(errors::fetch)
|
||||
.and_then(move |response| {
|
||||
|
||||
@@ -32,6 +32,7 @@ mod rpc;
|
||||
mod secretstore;
|
||||
mod traces;
|
||||
mod web3;
|
||||
mod private;
|
||||
|
||||
pub mod light;
|
||||
|
||||
@@ -51,3 +52,4 @@ pub use self::traces::TracesClient;
|
||||
pub use self::web3::Web3Client;
|
||||
pub use self::rpc::RpcClient;
|
||||
pub use self::secretstore::SecretStoreClient;
|
||||
pub use self::private::PrivateClient;
|
||||
|
||||
@@ -170,7 +170,7 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
|
||||
}
|
||||
|
||||
fn hash_content(&self, url: String) -> BoxFuture<H256> {
|
||||
let future = self.fetch.fetch(&url, Default::default()).then(move |result| {
|
||||
let future = self.fetch.get(&url, Default::default()).then(move |result| {
|
||||
result
|
||||
.map_err(errors::fetch)
|
||||
.and_then(move |response| {
|
||||
|
||||
122
rpc/src/v1/impls/private.rs
Normal file
122
rpc/src/v1/impls/private.rs
Normal file
@@ -0,0 +1,122 @@
|
||||
// Copyright 2015-2017 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Privte transaction signing RPC implementation.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use rlp::UntrustedRlp;
|
||||
|
||||
use ethcore_private_tx::Provider as PrivateTransactionManager;
|
||||
use ethereum_types::Address;
|
||||
use transaction::SignedTransaction;
|
||||
|
||||
use jsonrpc_core::{Error};
|
||||
use v1::types::{Bytes, PrivateTransactionReceipt, H160, H256, TransactionRequest, U256,
|
||||
BlockNumber, PrivateTransactionReceiptAndTransaction, CallRequest, block_number_to_id};
|
||||
use v1::traits::Private;
|
||||
use v1::metadata::Metadata;
|
||||
use v1::helpers::{errors, fake_sign};
|
||||
|
||||
/// Private transaction manager API endpoint implementation.
|
||||
pub struct PrivateClient {
|
||||
private: Option<Arc<PrivateTransactionManager>>,
|
||||
}
|
||||
|
||||
impl PrivateClient {
|
||||
/// Creates a new instance.
|
||||
pub fn new(private: Option<Arc<PrivateTransactionManager>>) -> Self {
|
||||
PrivateClient {
|
||||
private,
|
||||
}
|
||||
}
|
||||
|
||||
fn unwrap_manager(&self) -> Result<&PrivateTransactionManager, Error> {
|
||||
match self.private {
|
||||
Some(ref arc) => Ok(&**arc),
|
||||
None => Err(errors::public_unsupported(None)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Private for PrivateClient {
|
||||
type Metadata = Metadata;
|
||||
|
||||
fn send_transaction(&self, request: Bytes) -> Result<PrivateTransactionReceipt, Error> {
|
||||
let signed_transaction = UntrustedRlp::new(&request.into_vec()).as_val()
|
||||
.map_err(errors::rlp)
|
||||
.and_then(|tx| SignedTransaction::new(tx).map_err(errors::transaction))?;
|
||||
let client = self.unwrap_manager()?;
|
||||
let receipt = client.create_private_transaction(signed_transaction).map_err(|e| errors::private_message(e))?;
|
||||
Ok(receipt.into())
|
||||
}
|
||||
|
||||
fn compose_deployment_transaction(&self, block_number: BlockNumber, request: Bytes, validators: Vec<H160>, gas_price: U256) -> Result<PrivateTransactionReceiptAndTransaction, Error> {
|
||||
let signed_transaction = UntrustedRlp::new(&request.into_vec()).as_val()
|
||||
.map_err(errors::rlp)
|
||||
.and_then(|tx| SignedTransaction::new(tx).map_err(errors::transaction))?;
|
||||
let client = self.unwrap_manager()?;
|
||||
|
||||
let addresses: Vec<Address> = validators.into_iter().map(Into::into).collect();
|
||||
let id = match block_number {
|
||||
BlockNumber::Pending => return Err(errors::private_message_block_id_not_supported()),
|
||||
num => block_number_to_id(num)
|
||||
};
|
||||
|
||||
let (transaction, contract_address) = client.public_creation_transaction(id, &signed_transaction, addresses.as_slice(), gas_price.into())
|
||||
.map_err(|e| errors::private_message(e))?;
|
||||
let tx_hash = transaction.hash(None);
|
||||
let request = TransactionRequest {
|
||||
from: Some(signed_transaction.sender().into()),
|
||||
to: None,
|
||||
nonce: Some(transaction.nonce.into()),
|
||||
gas_price: Some(transaction.gas_price.into()),
|
||||
gas: Some(transaction.gas.into()),
|
||||
value: Some(transaction.value.into()),
|
||||
data: Some(transaction.data.into()),
|
||||
condition: None,
|
||||
};
|
||||
|
||||
Ok(PrivateTransactionReceiptAndTransaction {
|
||||
transaction: request,
|
||||
receipt: PrivateTransactionReceipt {
|
||||
transaction_hash: tx_hash.into(),
|
||||
contract_address: contract_address.map(|address| address.into()),
|
||||
status_code: 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn private_call(&self, meta: Self::Metadata, block_number: BlockNumber, request: CallRequest) -> Result<Bytes, Error> {
|
||||
let id = match block_number {
|
||||
BlockNumber::Pending => return Err(errors::private_message_block_id_not_supported()),
|
||||
num => block_number_to_id(num)
|
||||
};
|
||||
|
||||
let request = CallRequest::into(request);
|
||||
let signed = fake_sign::sign_call(request, meta.is_dapp())?;
|
||||
let client = self.unwrap_manager()?;
|
||||
let executed_result = client.private_call(id, &signed).map_err(|e| errors::private_message(e))?;
|
||||
Ok(executed_result.output.into())
|
||||
}
|
||||
|
||||
fn private_contract_key(&self, contract_address: H160) -> Result<H256, Error> {
|
||||
let client = self.unwrap_manager()?;
|
||||
let key = client.contract_key_id(&contract_address.into()).map_err(|e| errors::private_message(e))?;
|
||||
Ok(key.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pub mod informant;
|
||||
pub mod metadata;
|
||||
pub mod traits;
|
||||
|
||||
pub use self::traits::{Web3, Eth, EthFilter, EthPubSub, EthSigning, Net, Parity, ParityAccounts, ParitySet, ParitySigning, PubSub, Signer, Personal, Traces, Rpc, SecretStore};
|
||||
pub use self::traits::{Web3, Eth, EthFilter, EthPubSub, EthSigning, Net, Parity, ParityAccounts, ParitySet, ParitySigning, PubSub, Signer, Personal, Traces, Rpc, SecretStore, Private};
|
||||
pub use self::impls::*;
|
||||
pub use self::helpers::{NetworkSettings, block_import, dispatch};
|
||||
pub use self::metadata::Metadata;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::thread;
|
||||
use jsonrpc_core::futures::{self, Future};
|
||||
use fetch::{self, Fetch, Url};
|
||||
use fetch::{self, Fetch, Url, Method};
|
||||
use hyper;
|
||||
|
||||
/// Test implementation of fetcher. Will always return the same file.
|
||||
@@ -28,7 +28,7 @@ pub struct TestFetch;
|
||||
impl Fetch for TestFetch {
|
||||
type Result = Box<Future<Item = fetch::Response, Error = fetch::Error> + Send + 'static>;
|
||||
|
||||
fn fetch(&self, url: &str, abort: fetch::Abort) -> Self::Result {
|
||||
fn fetch(&self, url: &str, _method: Method, abort: fetch::Abort) -> Self::Result {
|
||||
let u = Url::parse(url).unwrap();
|
||||
let (tx, rx) = futures::oneshot();
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -31,6 +31,7 @@ pub mod signer;
|
||||
pub mod traces;
|
||||
pub mod rpc;
|
||||
pub mod secretstore;
|
||||
pub mod private;
|
||||
|
||||
pub use self::web3::Web3;
|
||||
pub use self::eth::{Eth, EthFilter};
|
||||
@@ -47,3 +48,4 @@ pub use self::signer::Signer;
|
||||
pub use self::traces::Traces;
|
||||
pub use self::rpc::Rpc;
|
||||
pub use self::secretstore::SecretStore;
|
||||
pub use self::private::Private;
|
||||
|
||||
45
rpc/src/v1/traits/private.rs
Normal file
45
rpc/src/v1/traits/private.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2015-2017 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! SecretStore-specific rpc interface.
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
|
||||
use v1::types::{Bytes, PrivateTransactionReceipt, H160, H256, U256, BlockNumber,
|
||||
PrivateTransactionReceiptAndTransaction, CallRequest};
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Private transaction management RPC interface.
|
||||
pub trait Private {
|
||||
type Metadata;
|
||||
|
||||
/// Sends private transaction; Transaction will be added to the validation queue and sent out when ready.
|
||||
#[rpc(name = "private_sendTransaction")]
|
||||
fn send_transaction(&self, Bytes) -> Result<PrivateTransactionReceipt, Error>;
|
||||
|
||||
/// Creates a transaction for contract's deployment from origin (signed transaction)
|
||||
#[rpc(name = "private_composeDeploymentTransaction")]
|
||||
fn compose_deployment_transaction(&self, BlockNumber, Bytes, Vec<H160>, U256) -> Result<PrivateTransactionReceiptAndTransaction, Error>;
|
||||
|
||||
/// Make a call to the private contract
|
||||
#[rpc(meta, name = "private_call")]
|
||||
fn private_call(&self, Self::Metadata, BlockNumber, CallRequest) -> Result<Bytes, Error>;
|
||||
|
||||
/// Retrieve the id of the key associated with the contract
|
||||
#[rpc(name = "private_contractKey")]
|
||||
fn private_contract_key(&self, H160) -> Result<H256, Error>;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ mod transaction_request;
|
||||
mod transaction_condition;
|
||||
mod uint;
|
||||
mod work;
|
||||
mod private_receipt;
|
||||
|
||||
pub mod pubsub;
|
||||
|
||||
@@ -80,6 +81,7 @@ pub use self::transaction_request::TransactionRequest;
|
||||
pub use self::transaction_condition::TransactionCondition;
|
||||
pub use self::uint::{U128, U256, U64};
|
||||
pub use self::work::Work;
|
||||
pub use self::private_receipt::{PrivateTransactionReceipt, PrivateTransactionReceiptAndTransaction};
|
||||
|
||||
// TODO [ToDr] Refactor to a proper type Vec of enums?
|
||||
/// Expected tracing type.
|
||||
|
||||
54
rpc/src/v1/types/private_receipt.rs
Normal file
54
rpc/src/v1/types/private_receipt.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2015-2017 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
use v1::types::{H160, H256, TransactionRequest};
|
||||
use ethcore_private_tx::{Receipt as EthPrivateReceipt};
|
||||
|
||||
/// Receipt
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PrivateTransactionReceipt {
|
||||
/// Transaction Hash
|
||||
#[serde(rename="transactionHash")]
|
||||
pub transaction_hash: H256,
|
||||
/// Private contract address
|
||||
#[serde(rename="contractAddress")]
|
||||
pub contract_address: Option<H160>,
|
||||
/// Status code
|
||||
#[serde(rename="status")]
|
||||
pub status_code: u8,
|
||||
}
|
||||
|
||||
impl From<EthPrivateReceipt> for PrivateTransactionReceipt {
|
||||
fn from(r: EthPrivateReceipt) -> Self {
|
||||
PrivateTransactionReceipt {
|
||||
transaction_hash: r.hash.into(),
|
||||
contract_address: r.contract_address.map(Into::into),
|
||||
status_code: r.status_code.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Receipt and Transaction
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PrivateTransactionReceiptAndTransaction {
|
||||
/// Receipt
|
||||
#[serde(rename="receipt")]
|
||||
pub receipt: PrivateTransactionReceipt,
|
||||
/// Transaction
|
||||
#[serde(rename="transaction")]
|
||||
pub transaction: TransactionRequest,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user