Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 35bbf11

Browse files
HCastanoniklasad1
authored andcommitted
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 <[email protected]> * Rename call-contract crate to ethcore-call-contract
1 parent 4f1e1e8 commit 35bbf11

16 files changed

+113
-21
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ethabi-derive = "6.0"
2121
ethash = { path = "../ethash" }
2222
ethcore-blockchain = { path = "./blockchain" }
2323
ethcore-bloom-journal = { path = "../util/bloom" }
24+
ethcore-call-contract = { path = "./call-contract" }
2425
ethcore-db = { path = "./db" }
2526
ethcore-io = { path = "../util/io" }
2627
ethcore-miner = { path = "../miner" }

ethcore/call-contract/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "ethcore-call-contract"
3+
version = "0.1.0"
4+
license = "GPL-3.0"
5+
authors = ["Parity Technologies <[email protected]>"]
6+
edition = "2018"
7+
8+
[dependencies]
9+
types = { path = "../types", package = "common-types" }
10+
ethereum-types = "0.4"
11+
bytes = { version = "0.1", package = "parity-bytes" }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity Ethereum.
3+
4+
// Parity Ethereum is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity Ethereum is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Provides CallContract and RegistryInfo traits
18+
19+
use bytes::Bytes;
20+
use ethereum_types::Address;
21+
use types::ids::BlockId;
22+
23+
/// Provides `call_contract` method
24+
pub trait CallContract {
25+
/// Like `call`, but with various defaults. Designed to be used for calling contracts.
26+
fn call_contract(&self, id: BlockId, address: Address, data: Bytes) -> Result<Bytes, String>;
27+
}
28+
29+
/// Provides information on a blockchain service and it's registry
30+
pub trait RegistryInfo {
31+
/// Get the address of a particular blockchain service, if available.
32+
fn registry_address(&self, name: String, block: BlockId) -> Option<Address>;
33+
}

ethcore/call-contract/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity Ethereum.
3+
4+
// Parity Ethereum is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity Ethereum is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#![warn(missing_docs)]
18+
19+
//! Call Contract module
20+
//!
21+
//! This crate exposes traits required to call contracts at particular block.
22+
//! All utilities that depend on on-chain data should use those traits to access it.
23+
24+
pub mod call_contract;
25+
26+
// Re-export
27+
pub use self::call_contract::*;

ethcore/src/client/client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::time::{Instant, Duration};
2323

2424
use blockchain::{BlockReceipts, BlockChain, BlockChainDB, BlockProvider, TreeRoute, ImportRoute, TransactionAddress, ExtrasInsert, BlockNumberKey};
2525
use bytes::Bytes;
26+
use call_contract::{CallContract, RegistryInfo};
2627
use ethcore_miner::pool::VerifiedTransaction;
2728
use ethereum_types::{H256, Address, U256};
2829
use evm::Schedule;
@@ -46,8 +47,8 @@ use vm::{EnvInfo, LastHashes};
4647
use block::{IsBlock, LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock};
4748
use client::ancient_import::AncientVerifier;
4849
use client::{
49-
Nonce, Balance, ChainInfo, BlockInfo, CallContract, TransactionInfo,
50-
RegistryInfo, ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock,
50+
Nonce, Balance, ChainInfo, BlockInfo, TransactionInfo,
51+
ReopenBlock, PrepareOpenBlock, ScheduleInfo, ImportSealedBlock,
5152
BroadcastProposalBlock, ImportBlock, StateOrBlock, StateInfo, StateClient, Call,
5253
AccountData, BlockChain as BlockChainTrait, BlockProducer, SealedBlockImporter,
5354
ClientIoMessage, BlockChainReset

ethcore/src/client/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub use self::io_message::ClientIoMessage;
3636
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
3737
pub use self::chain_notify::{ChainNotify, NewBlocks, ChainRoute, ChainRouteType, ChainMessageType};
3838
pub use self::traits::{
39-
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, CallContract, TransactionInfo, RegistryInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
40-
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter,
41-
BadBlocks, BlockChainReset
39+
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, PrepareOpenBlock, TransactionInfo, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock,
40+
StateOrBlock, StateClient, Call, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, BadBlocks,
41+
BlockChainReset
4242
};
4343
pub use state::StateInfo;
4444
pub use self::traits::{BlockChainClient, EngineClient, ProvingBlockChainClient, IoClient};
@@ -48,6 +48,9 @@ pub use types::trace_filter::Filter as TraceFilter;
4848
pub use types::pruning_info::PruningInfo;
4949
pub use types::call_analytics::CallAnalytics;
5050

51+
// TODO: Get rid of re-exports: https://github.com/paritytech/parity-ethereum/issues/10130
52+
pub use call_contract::{CallContract, RegistryInfo};
53+
5154
pub use executive::{Executed, Executive, TransactOptions};
5255
pub use vm::{LastHashes, EnvInfo};
5356

ethcore/src/client/test_client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ use types::views::BlockView;
4949
use vm::Schedule;
5050

5151
use block::{OpenBlock, SealedBlock, ClosedBlock};
52+
use call_contract::{CallContract, RegistryInfo};
5253
use client::{
53-
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, CallContract, TransactionInfo, RegistryInfo,
54+
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, TransactionInfo,
5455
PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode,
5556
TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics,
5657
ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, StateOrBlock,

ethcore/src/client/traits.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::sync::Arc;
1919

2020
use blockchain::{BlockReceipts, TreeRoute};
2121
use bytes::Bytes;
22+
use call_contract::{CallContract, RegistryInfo};
2223
use ethcore_miner::pool::VerifiedTransaction;
2324
use ethereum_types::{H256, U256, Address};
2425
use evm::Schedule;
@@ -157,25 +158,13 @@ pub trait StateClient {
157158
/// Provides various blockchain information, like block header, chain state etc.
158159
pub trait BlockChain: ChainInfo + BlockInfo + TransactionInfo {}
159160

160-
/// Provides information on a blockchain service and it's registry
161-
pub trait RegistryInfo {
162-
/// Get the address of a particular blockchain service, if available.
163-
fn registry_address(&self, name: String, block: BlockId) -> Option<Address>;
164-
}
165-
166161
// FIXME Why these methods belong to BlockChainClient and not MiningBlockChainClient?
167162
/// Provides methods to import block into blockchain
168163
pub trait ImportBlock {
169164
/// Import a block into the blockchain.
170165
fn import_block(&self, block: Unverified) -> EthcoreResult<H256>;
171166
}
172167

173-
/// Provides `call_contract` method
174-
pub trait CallContract {
175-
/// Like `call`, but with various defaults. Designed to be used for calling contracts.
176-
fn call_contract(&self, id: BlockId, address: Address, data: Bytes) -> Result<Bytes, String>;
177-
}
178-
179168
/// Provides `call` and `call_many` methods
180169
pub trait Call {
181170
/// Type representing chain state

ethcore/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
extern crate ansi_term;
6161
extern crate bn;
6262
extern crate byteorder;
63+
extern crate ethcore_call_contract as call_contract;
6364
extern crate common_types as types;
6465
extern crate crossbeam;
6566
extern crate ethabi;

ethcore/src/miner/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
//! Keeps track of transactions and currently sealed pending block.
2121
2222
mod miner;
23-
mod service_transaction_checker;
2423

2524
pub mod pool_client;
2625
#[cfg(feature = "stratum")]

ethcore/src/miner/pool_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::{
2525
use ethereum_types::{H256, U256, Address};
2626
use ethcore_miner::pool;
2727
use ethcore_miner::pool::client::NonceClient;
28+
use ethcore_miner::service_transaction_checker::ServiceTransactionChecker;
2829
use types::transaction::{
2930
self,
3031
UnverifiedTransaction,
@@ -37,7 +38,6 @@ use account_provider::AccountProvider;
3738
use client::{TransactionId, BlockInfo, CallContract, Nonce};
3839
use engines::EthEngine;
3940
use miner;
40-
use miner::service_transaction_checker::ServiceTransactionChecker;
4141
use transaction_ext::Transaction;
4242

4343
/// Cache for state nonces.

miner/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ url = { version = "1", optional = true }
1717
ansi_term = "0.10"
1818
common-types = { path = "../ethcore/types" }
1919
error-chain = "0.12"
20+
ethabi = "6.0"
21+
ethabi-derive = "6.0"
22+
ethabi-contract = "6.0"
23+
ethcore-call-contract = { path = "../ethcore/call-contract" }
2024
ethereum-types = "0.4"
2125
futures = "0.1"
2226
heapsize = "0.4"

miner/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
2222
extern crate ansi_term;
2323
extern crate common_types as types;
24+
extern crate ethabi;
25+
extern crate ethcore_call_contract as call_contract;
2426
extern crate ethereum_types;
2527
extern crate futures;
2628
extern crate heapsize;
@@ -33,6 +35,10 @@ extern crate price_info;
3335
extern crate rlp;
3436
extern crate transaction_pool as txpool;
3537

38+
#[macro_use]
39+
extern crate ethabi_contract;
40+
#[macro_use]
41+
extern crate ethabi_derive;
3642
#[macro_use]
3743
extern crate error_chain;
3844
#[macro_use]
@@ -52,5 +58,6 @@ pub mod external;
5258
pub mod gas_price_calibrator;
5359
pub mod gas_pricer;
5460
pub mod pool;
61+
pub mod service_transaction_checker;
5562
#[cfg(feature = "work-notify")]
5663
pub mod work_notify;

ethcore/src/miner/service_transaction_checker.rs renamed to miner/src/service_transaction_checker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
//! A service transactions contract checker.
1818
19-
use client::{RegistryInfo, CallContract, BlockId};
19+
use call_contract::{CallContract, RegistryInfo};
20+
use types::ids::BlockId;
2021
use types::transaction::SignedTransaction;
2122
use ethabi::FunctionOutputDecoder;
2223

0 commit comments

Comments
 (0)