Extract CallContract and RegistryInfo traits into their own crate (#10178)

* Create call-contract crate

* Add license

* First attempt at using extracted CallContract trait

* Remove unneeded `extern crate` calls

* Move RegistryInfo trait into call-contract crate

* Move service-transaction-checker from ethcore to ethcore-miner

* Update Cargo.lock file

* Re-export call_contract

* Merge CallContract and RegistryInfo imports

* Remove commented code

* Add documentation to call_contract crate

* Add TODO for removal of re-exports

* Update call-contract crate description

Co-Authored-By: HCastano <HCastano@users.noreply.github.com>

* Rename call-contract crate to ethcore-call-contract
This commit is contained in:
Hernando Castano 2019-01-16 19:52:21 +01:00 committed by Niklas Adolfsson
parent 4f1e1e8870
commit 35bbf11ba5
16 changed files with 113 additions and 21 deletions

14
Cargo.lock generated
View File

@ -695,6 +695,7 @@ dependencies = [
"ethash 1.12.0", "ethash 1.12.0",
"ethcore-blockchain 0.1.0", "ethcore-blockchain 0.1.0",
"ethcore-bloom-journal 0.1.0", "ethcore-bloom-journal 0.1.0",
"ethcore-call-contract 0.1.0",
"ethcore-db 0.1.0", "ethcore-db 0.1.0",
"ethcore-io 1.12.0", "ethcore-io 1.12.0",
"ethcore-miner 1.12.0", "ethcore-miner 1.12.0",
@ -784,6 +785,15 @@ dependencies = [
"siphasher 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "siphasher 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "ethcore-call-contract"
version = "0.1.0"
dependencies = [
"common-types 0.1.0",
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "ethcore-db" name = "ethcore-db"
version = "0.1.0" version = "0.1.0"
@ -879,7 +889,11 @@ dependencies = [
"common-types 0.1.0", "common-types 0.1.0",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ethash 1.12.0", "ethash 1.12.0",
"ethcore-call-contract 0.1.0",
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethkey 0.3.0", "ethkey 0.3.0",
"fetch 0.1.0", "fetch 0.1.0",

View File

@ -21,6 +21,7 @@ ethabi-derive = "6.0"
ethash = { path = "../ethash" } ethash = { path = "../ethash" }
ethcore-blockchain = { path = "./blockchain" } ethcore-blockchain = { path = "./blockchain" }
ethcore-bloom-journal = { path = "../util/bloom" } ethcore-bloom-journal = { path = "../util/bloom" }
ethcore-call-contract = { path = "./call-contract" }
ethcore-db = { path = "./db" } ethcore-db = { path = "./db" }
ethcore-io = { path = "../util/io" } ethcore-io = { path = "../util/io" }
ethcore-miner = { path = "../miner" } ethcore-miner = { path = "../miner" }

View File

@ -0,0 +1,11 @@
[package]
name = "ethcore-call-contract"
version = "0.1.0"
license = "GPL-3.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
types = { path = "../types", package = "common-types" }
ethereum-types = "0.4"
bytes = { version = "0.1", package = "parity-bytes" }

View File

@ -0,0 +1,33 @@
// 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 <http://www.gnu.org/licenses/>.
//! Provides CallContract and RegistryInfo traits
use bytes::Bytes;
use ethereum_types::Address;
use types::ids::BlockId;
/// Provides `call_contract` method
pub trait CallContract {
/// Like `call`, but with various defaults. Designed to be used for calling contracts.
fn call_contract(&self, id: BlockId, address: Address, data: Bytes) -> Result<Bytes, String>;
}
/// Provides information on a blockchain service and it's registry
pub trait RegistryInfo {
/// Get the address of a particular blockchain service, if available.
fn registry_address(&self, name: String, block: BlockId) -> Option<Address>;
}

View File

@ -0,0 +1,27 @@
// 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 <http://www.gnu.org/licenses/>.
#![warn(missing_docs)]
//! Call Contract module
//!
//! This crate exposes traits required to call contracts at particular block.
//! All utilities that depend on on-chain data should use those traits to access it.
pub mod call_contract;
// Re-export
pub use self::call_contract::*;

View File

@ -23,6 +23,7 @@ use std::time::{Instant, Duration};
use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, ImportRoute, TransactionAddress, ExtrasInsert, BlockNumberKey}; use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, ImportRoute, TransactionAddress, ExtrasInsert, BlockNumberKey};
use bytes::Bytes; use bytes::Bytes;
use call_contract::{CallContract, RegistryInfo};
use ethcore_miner::pool::VerifiedTransaction; use ethcore_miner::pool::VerifiedTransaction;
use ethereum_types::{H256, Address, U256}; use ethereum_types::{H256, Address, U256};
use evm::Schedule; use evm::Schedule;
@ -46,8 +47,8 @@ use vm::{EnvInfo, LastHashes};
use block::{IsBlock, LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock}; use block::{IsBlock, LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock};
use client::ancient_import::AncientVerifier; use client::ancient_import::AncientVerifier;
use client::{ use client::{
Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo, Nonce, Balance, ChainInfo, BlockInfo, TransactionInfo,
RegistryInfo, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock,
BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call, BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call,
AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter, AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter,
ClientIoMessage, BlockChainReset ClientIoMessage, BlockChainReset

View File

@ -36,9 +36,9 @@ pub use self::io_message::ClientIoMessage;
pub use self::test_client::{TestBlockChainClient, EachBlockWith}; pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType}; pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType};
pub use self::traits::{ pub use self::traits::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, CallContract, TransactionInfo, RegistryInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, TransactionInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, BadBlocks,
BadBlocks, BlockChainReset BlockChainReset
}; };
pub use state::StateInfo; pub use state::StateInfo;
pub use self::traits::{BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient}; pub use self::traits::{BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient};
@ -48,6 +48,9 @@ pub use types::trace_filter::Filter as TraceFilter;
pub use types::pruning_info::PruningInfo; pub use types::pruning_info::PruningInfo;
pub use types::call_analytics::CallAnalytics; pub use types::call_analytics::CallAnalytics;
// TODO: Get rid of re-exports: https://github.com/paritytech/parity-ethereum/issues/10130
pub use call_contract::{CallContract, RegistryInfo};
pub use executive::{Executed, Executive, TransactOptions}; pub use executive::{Executed, Executive, TransactOptions};
pub use vm::{LastHashes, EnvInfo}; pub use vm::{LastHashes, EnvInfo};

View File

@ -49,8 +49,9 @@ use types::views::BlockView;
use vm::Schedule; use vm::Schedule;
use block::{OpenBlock, SealedBlock, ClosedBlock}; use block::{OpenBlock, SealedBlock, ClosedBlock};
use call_contract::{CallContract, RegistryInfo};
use client::{ use client::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, CallContract, TransactionInfo, RegistryInfo, Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, TransactionInfo,
PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode, PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode,
TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics, TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics,
ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, StateOrBlock, ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, StateOrBlock,

View File

@ -19,6 +19,7 @@ use std::sync::Arc;
use blockchain::{BlockReceipts, TreeRoute}; use blockchain::{BlockReceipts, TreeRoute};
use bytes::Bytes; use bytes::Bytes;
use call_contract::{CallContract, RegistryInfo};
use ethcore_miner::pool::VerifiedTransaction; use ethcore_miner::pool::VerifiedTransaction;
use ethereum_types::{H256, U256, Address}; use ethereum_types::{H256, U256, Address};
use evm::Schedule; use evm::Schedule;
@ -157,12 +158,6 @@ pub trait StateClient {
/// Provides various blockchain information, like block header, chain state etc. /// Provides various blockchain information, like block header, chain state etc.
pub trait BlockChain: ChainInfo + BlockInfo + TransactionInfo {} pub trait BlockChain: ChainInfo + BlockInfo + TransactionInfo {}
/// Provides information on a blockchain service and it's registry
pub trait RegistryInfo {
/// Get the address of a particular blockchain service, if available.
fn registry_address(&self, name: String, block: BlockId) -> Option<Address>;
}
// FIXME Why these methods belong to BlockChainClient and not MiningBlockChainClient? // FIXME Why these methods belong to BlockChainClient and not MiningBlockChainClient?
/// Provides methods to import block into blockchain /// Provides methods to import block into blockchain
pub trait ImportBlock { pub trait ImportBlock {
@ -170,12 +165,6 @@ pub trait ImportBlock {
fn import_block(&self, block: Unverified) -> EthcoreResult<H256>; fn import_block(&self, block: Unverified) -> EthcoreResult<H256>;
} }
/// Provides `call_contract` method
pub trait CallContract {
/// Like `call`, but with various defaults. Designed to be used for calling contracts.
fn call_contract(&self, id: BlockId, address: Address, data: Bytes) -> Result<Bytes, String>;
}
/// Provides `call` and `call_many` methods /// Provides `call` and `call_many` methods
pub trait Call { pub trait Call {
/// Type representing chain state /// Type representing chain state

View File

@ -60,6 +60,7 @@
extern crate ansi_term; extern crate ansi_term;
extern crate bn; extern crate bn;
extern crate byteorder; extern crate byteorder;
extern crate ethcore_call_contract as call_contract;
extern crate common_types as types; extern crate common_types as types;
extern crate crossbeam; extern crate crossbeam;
extern crate ethabi; extern crate ethabi;

View File

@ -20,7 +20,6 @@
//! Keeps track of transactions and currently sealed pending block. //! Keeps track of transactions and currently sealed pending block.
mod miner; mod miner;
mod service_transaction_checker;
pub mod pool_client; pub mod pool_client;
#[cfg(feature = "stratum")] #[cfg(feature = "stratum")]

View File

@ -25,6 +25,7 @@ use std::{
use ethereum_types::{H256, U256, Address}; use ethereum_types::{H256, U256, Address};
use ethcore_miner::pool; use ethcore_miner::pool;
use ethcore_miner::pool::client::NonceClient; use ethcore_miner::pool::client::NonceClient;
use ethcore_miner::service_transaction_checker::ServiceTransactionChecker;
use types::transaction::{ use types::transaction::{
self, self,
UnverifiedTransaction, UnverifiedTransaction,
@ -37,7 +38,6 @@ use account_provider::AccountProvider;
use client::{TransactionId, BlockInfo, CallContract, Nonce}; use client::{TransactionId, BlockInfo, CallContract, Nonce};
use engines::EthEngine; use engines::EthEngine;
use miner; use miner;
use miner::service_transaction_checker::ServiceTransactionChecker;
use transaction_ext::Transaction; use transaction_ext::Transaction;
/// Cache for state nonces. /// Cache for state nonces.

View File

@ -17,6 +17,10 @@ url = { version = "1", optional = true }
ansi_term = "0.10" ansi_term = "0.10"
common-types = { path = "../ethcore/types" } common-types = { path = "../ethcore/types" }
error-chain = "0.12" error-chain = "0.12"
ethabi = "6.0"
ethabi-derive = "6.0"
ethabi-contract = "6.0"
ethcore-call-contract = { path = "../ethcore/call-contract" }
ethereum-types = "0.4" ethereum-types = "0.4"
futures = "0.1" futures = "0.1"
heapsize = "0.4" heapsize = "0.4"

View File

@ -21,6 +21,8 @@
extern crate ansi_term; extern crate ansi_term;
extern crate common_types as types; extern crate common_types as types;
extern crate ethabi;
extern crate ethcore_call_contract as call_contract;
extern crate ethereum_types; extern crate ethereum_types;
extern crate futures; extern crate futures;
extern crate heapsize; extern crate heapsize;
@ -33,6 +35,10 @@ extern crate price_info;
extern crate rlp; extern crate rlp;
extern crate transaction_pool as txpool; extern crate transaction_pool as txpool;
#[macro_use]
extern crate ethabi_contract;
#[macro_use]
extern crate ethabi_derive;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate error_chain;
#[macro_use] #[macro_use]
@ -52,5 +58,6 @@ pub mod external;
pub mod gas_price_calibrator; pub mod gas_price_calibrator;
pub mod gas_pricer; pub mod gas_pricer;
pub mod pool; pub mod pool;
pub mod service_transaction_checker;
#[cfg(feature = "work-notify")] #[cfg(feature = "work-notify")]
pub mod work_notify; pub mod work_notify;

View File

@ -16,7 +16,8 @@
//! A service transactions contract checker. //! A service transactions contract checker.
use client::{RegistryInfo, CallContract, BlockId}; use call_contract::{CallContract, RegistryInfo};
use types::ids::BlockId;
use types::transaction::SignedTransaction; use types::transaction::SignedTransaction;
use ethabi::FunctionOutputDecoder; use ethabi::FunctionOutputDecoder;