Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ blooms-db = { path = "../util/blooms-db" }
criterion = "0.3"
engine = { path = "./engine", features = ["test-helpers"] }
env_logger = "0.5"
ethash = { path = "../ethash" }
ethcore-accounts = { path = "../accounts" }
ethcore-builtin = { path = "./builtin" }
ethjson = { path = "../json", features = ["test-helpers"] }
Expand Down
64 changes: 61 additions & 3 deletions ethcore/client-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use common_types::{
pruning_info::PruningInfo,
receipt::LocalizedReceipt,
trace_filter::Filter as TraceFilter,
transaction::{self, LocalizedTransaction, CallError, SignedTransaction, UnverifiedTransaction},
transaction::{self, Action, LocalizedTransaction, CallError, SignedTransaction, UnverifiedTransaction},
tree_route::TreeRoute,
verification::{VerificationQueueInfo, Unverified},
};
Expand Down Expand Up @@ -395,8 +395,66 @@ pub trait BlockChainClient:
/// Returns information about pruning/data availability.
fn pruning_info(&self) -> PruningInfo;

/// Schedule state-altering transaction to be executed on the next pending block.
fn transact_contract(&self, address: Address, data: Bytes) -> Result<(), transaction::Error>;
/// Returns a transaction signed with the key configured in the engine signer.
fn create_transaction(&self, tx_request: TransactionRequest) -> Result<SignedTransaction, transaction::Error>;

/// Schedule state-altering transaction to be executed on the next pending
/// block with the given gas and nonce parameters.
fn transact(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error>;
}

/// The data required for a `Client` to create a transaction.
///
/// Gas limit, gas price, or nonce can be set explicitly, e.g. to create service
/// transactions with zero gas price, or sequences of transactions with consecutive nonces.
pub struct TransactionRequest {
pub action: Action,
pub data: Bytes,
pub gas: Option<U256>,
pub gas_price: Option<U256>,
pub nonce: Option<U256>,
}

impl TransactionRequest {
/// Creates a request to call a contract at `address` with the specified call data.
pub fn call(address: Address, data: Bytes) -> TransactionRequest {
TransactionRequest {
action: Action::Call(address),
data,
gas: None,
gas_price: None,
nonce: None,
}
}

/// Creates a request to create a new contract, with the specified bytecode.
pub fn create(data: Bytes) -> TransactionRequest {
TransactionRequest {
action: Action::Create,
data,
gas: None,
gas_price: None,
nonce: None,
}
}

/// Sets a gas limit. If this is not specified, a sensible default is used.
pub fn gas(mut self, gas: U256) -> TransactionRequest {
self.gas = Some(gas);
self
}

/// Sets a gas price. If this is not specified, a sensible default is used.
pub fn gas_price(mut self, gas_price: U256) -> TransactionRequest {
self.gas_price = Some(gas_price);
self
}

/// Sets a nonce. If this is not specified, the appropriate latest nonce for the author is used.
pub fn nonce(mut self, nonce: U256) -> TransactionRequest {
self.nonce = Some(nonce);
self
}
}

/// resets the blockchain
Expand Down
10 changes: 9 additions & 1 deletion ethcore/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use common_types::{
},
errors::{EthcoreError as Error, EngineError},
snapshot::Snapshotting,
transaction::{self, UnverifiedTransaction},
transaction::{self, SignedTransaction, UnverifiedTransaction},
};
use client_traits::EngineClient;

Expand Down Expand Up @@ -185,6 +185,14 @@ pub trait Engine: Sync + Send {
/// Allow mutating the header during seal generation. Currently only used by Clique.
fn on_seal_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> { Ok(()) }

/// Returns a list of transactions for a new block if we are the author.
///
/// This is called when the miner prepares a new block that this node will author and seal. It returns a list of
/// transactions that will be added to the block before any other transactions from the queue.
fn generate_engine_transactions(&self, _block: &ExecutedBlock) -> Result<Vec<SignedTransaction>, Error> {
Ok(Vec::new())
}

/// Returns the engine's current sealing state.
fn sealing_state(&self) -> SealingState { SealingState::External }

Expand Down
16 changes: 15 additions & 1 deletion ethcore/engine/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! A signer used by Engines which need to sign messages.

use ethereum_types::{H256, Address};
use parity_crypto::publickey::{Signature, KeyPair, Error};
use parity_crypto::publickey::{ecies, Public, Signature, KeyPair, Error};

/// Everything that an Engine needs to sign messages.
pub trait EngineSigner: Send + Sync {
Expand All @@ -26,6 +26,12 @@ pub trait EngineSigner: Send + Sync {

/// Signing address
fn address(&self) -> Address;

/// Decrypt a message that was encrypted to this signer's key.
fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, Error>;

/// The signer's public key, if available.
fn public(&self) -> Option<Public>;
}

/// Creates a new `EngineSigner` from given key pair.
Expand All @@ -40,7 +46,15 @@ impl EngineSigner for Signer {
parity_crypto::publickey::sign(self.0.secret(), &hash)
}

fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, Error> {
ecies::decrypt(self.0.secret(), auth_data, cipher)
}

fn address(&self) -> Address {
self.0.address()
}

fn public(&self) -> Option<Public> {
Some(*self.0.public())
}
}
13 changes: 12 additions & 1 deletion ethcore/engine/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;

use ethereum_types::{Address, H256};
use ethkey::Password;
use parity_crypto::publickey::{Signature, Error};
use parity_crypto::publickey::{Public, Signature, Error};
use log::warn;
use accounts::{self, AccountProvider, SignError};

Expand All @@ -44,7 +44,18 @@ impl EngineSigner for (Arc<AccountProvider>, Address, Password) {
}
}

fn decrypt(&self, auth_data: &[u8], cipher: &[u8]) -> Result<Vec<u8>, Error> {
self.0.decrypt(self.1, None, auth_data, cipher).map_err(|e| {
warn!("Unable to decrypt message: {:?}", e);
Error::InvalidMessage
})
}

fn address(&self) -> Address {
self.1
}

fn public(&self) -> Option<Public> {
self.0.account_public(self.1, &self.2).ok()
}
}
6 changes: 6 additions & 0 deletions ethcore/engines/authority-round/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ license = "GPL-3.0"
block-reward = { path = "../../block-reward" }
client-traits = { path = "../../client-traits" }
common-types = { path = "../../types" }
derive_more = "0.15.0"
ethabi = "9.0.1"
ethabi-contract = "9.0.0"
ethabi-derive = "9.0.1"
ethereum-types = "0.8.0"
ethjson = { path = "../../../json" }
parity-crypto = { version = "0.4.2", features = ["publickey"] }
Expand All @@ -22,7 +26,9 @@ log = "0.4"
lru-cache = "0.1"
machine = { path = "../../machine" }
macros = { path = "../../../util/macros" }
parity-bytes = "0.1"
parking_lot = "0.9"
rand = "0.7"
rlp = "0.4.0"
time-utils = { path = "../../../util/time-utils" }
unexpected = { path = "../../../util/unexpected" }
Expand Down
Loading