Set zero nonce and gasprice for calls by default (#6954)
This commit is contained in:
parent
f72858ee0a
commit
60bb2d9c74
@ -348,7 +348,7 @@ impl FullDependencies {
|
|||||||
).to_delegate())
|
).to_delegate())
|
||||||
},
|
},
|
||||||
Api::Traces => {
|
Api::Traces => {
|
||||||
handler.extend_with(TracesClient::new(&self.client, &self.miner).to_delegate())
|
handler.extend_with(TracesClient::new(&self.client).to_delegate())
|
||||||
},
|
},
|
||||||
Api::Rpc => {
|
Api::Rpc => {
|
||||||
let modules = to_modules(&apis);
|
let modules = to_modules(&apis);
|
||||||
|
@ -14,22 +14,13 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
use ethcore::client::MiningBlockChainClient;
|
|
||||||
use ethcore::miner::MinerService;
|
|
||||||
use ethcore::transaction::{Transaction, SignedTransaction, Action};
|
use ethcore::transaction::{Transaction, SignedTransaction, Action};
|
||||||
use bigint::prelude::U256;
|
use bigint::prelude::U256;
|
||||||
|
|
||||||
use jsonrpc_core::Error;
|
use jsonrpc_core::Error;
|
||||||
use v1::helpers::CallRequest;
|
use v1::helpers::CallRequest;
|
||||||
use v1::helpers::dispatch::default_gas_price;
|
|
||||||
|
|
||||||
pub fn sign_call<C: MiningBlockChainClient, M: MinerService> (
|
pub fn sign_call(request: CallRequest, gas_cap: bool) -> Result<SignedTransaction, Error> {
|
||||||
client: &Arc<C>,
|
|
||||||
miner: &Arc<M>,
|
|
||||||
request: CallRequest,
|
|
||||||
gas_cap: bool,
|
|
||||||
) -> Result<SignedTransaction, Error> {
|
|
||||||
let max_gas = 50_000_000.into();
|
let max_gas = 50_000_000.into();
|
||||||
let gas = match request.gas {
|
let gas = match request.gas {
|
||||||
Some(gas) if gas_cap && gas > max_gas => {
|
Some(gas) if gas_cap && gas > max_gas => {
|
||||||
@ -43,10 +34,10 @@ pub fn sign_call<C: MiningBlockChainClient, M: MinerService> (
|
|||||||
let from = request.from.unwrap_or(0.into());
|
let from = request.from.unwrap_or(0.into());
|
||||||
|
|
||||||
Ok(Transaction {
|
Ok(Transaction {
|
||||||
nonce: request.nonce.unwrap_or_else(|| client.latest_nonce(&from)),
|
nonce: request.nonce.unwrap_or_else(|| 0.into()),
|
||||||
action: request.to.map_or(Action::Create, Action::Call),
|
action: request.to.map_or(Action::Create, Action::Call),
|
||||||
gas,
|
gas,
|
||||||
gas_price: request.gas_price.unwrap_or_else(|| default_gas_price(&**client, &**miner)),
|
gas_price: request.gas_price.unwrap_or_else(|| 0.into()),
|
||||||
value: request.value.unwrap_or(0.into()),
|
value: request.value.unwrap_or(0.into()),
|
||||||
data: request.data.unwrap_or_default(),
|
data: request.data.unwrap_or_default(),
|
||||||
}.fake_sign(from))
|
}.fake_sign(from))
|
||||||
|
@ -625,7 +625,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
|||||||
|
|
||||||
fn call(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
fn call(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes, Error> {
|
||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
let signed = try_bf!(fake_sign::sign_call(request, meta.is_dapp()));
|
||||||
|
|
||||||
let num = num.unwrap_or_default();
|
let num = num.unwrap_or_default();
|
||||||
let result = self.client.call(&signed, Default::default(), num.into());
|
let result = self.client.call(&signed, Default::default(), num.into());
|
||||||
@ -638,7 +638,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
|
|||||||
|
|
||||||
fn estimate_gas(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
fn estimate_gas(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256, Error> {
|
||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = try_bf!(fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp()));
|
let signed = try_bf!(fake_sign::sign_call(request, meta.is_dapp()));
|
||||||
Box::new(future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into())
|
Box::new(future::done(self.client.estimate_gas(&signed, num.unwrap_or_default().into())
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.map_err(errors::call)
|
.map_err(errors::call)
|
||||||
|
@ -418,7 +418,7 @@ impl<C, M, U> Parity for ParityClient<C, M, U> where
|
|||||||
let requests = requests
|
let requests = requests
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|request| Ok((
|
.map(|request| Ok((
|
||||||
fake_sign::sign_call(&self.client, &self.miner, request.into(), meta.is_dapp())?,
|
fake_sign::sign_call(request.into(), meta.is_dapp())?,
|
||||||
Default::default()
|
Default::default()
|
||||||
)))
|
)))
|
||||||
.collect::<Result<Vec<_>, Error>>()?;
|
.collect::<Result<Vec<_>, Error>>()?;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ethcore::client::{MiningBlockChainClient, CallAnalytics, TransactionId, TraceId};
|
use ethcore::client::{MiningBlockChainClient, CallAnalytics, TransactionId, TraceId};
|
||||||
use ethcore::miner::MinerService;
|
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use rlp::UntrustedRlp;
|
use rlp::UntrustedRlp;
|
||||||
|
|
||||||
@ -39,22 +38,20 @@ fn to_call_analytics(flags: TraceOptions) -> CallAnalytics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Traces api implementation.
|
/// Traces api implementation.
|
||||||
pub struct TracesClient<C, M> {
|
pub struct TracesClient<C> {
|
||||||
client: Arc<C>,
|
client: Arc<C>,
|
||||||
miner: Arc<M>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, M> TracesClient<C, M> {
|
impl<C> TracesClient<C> {
|
||||||
/// Creates new Traces client.
|
/// Creates new Traces client.
|
||||||
pub fn new(client: &Arc<C>, miner: &Arc<M>) -> Self {
|
pub fn new(client: &Arc<C>) -> Self {
|
||||||
TracesClient {
|
TracesClient {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
miner: miner.clone(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, M> Traces for TracesClient<C, M> where C: MiningBlockChainClient + 'static, M: MinerService + 'static {
|
impl<C> Traces for TracesClient<C> where C: MiningBlockChainClient + 'static {
|
||||||
type Metadata = Metadata;
|
type Metadata = Metadata;
|
||||||
|
|
||||||
fn filter(&self, filter: TraceFilter) -> Result<Option<Vec<LocalizedTrace>>, Error> {
|
fn filter(&self, filter: TraceFilter) -> Result<Option<Vec<LocalizedTrace>>, Error> {
|
||||||
@ -86,7 +83,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: MiningBlockChainClient + 'stat
|
|||||||
let block = block.unwrap_or_default();
|
let block = block.unwrap_or_default();
|
||||||
|
|
||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())?;
|
let signed = fake_sign::sign_call(request, meta.is_dapp())?;
|
||||||
|
|
||||||
self.client.call(&signed, to_call_analytics(flags), block.into())
|
self.client.call(&signed, to_call_analytics(flags), block.into())
|
||||||
.map(TraceResults::from)
|
.map(TraceResults::from)
|
||||||
@ -99,7 +96,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: MiningBlockChainClient + 'stat
|
|||||||
let requests = requests.into_iter()
|
let requests = requests.into_iter()
|
||||||
.map(|(request, flags)| {
|
.map(|(request, flags)| {
|
||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = fake_sign::sign_call(&self.client, &self.miner, request, meta.is_dapp())?;
|
let signed = fake_sign::sign_call(request, meta.is_dapp())?;
|
||||||
Ok((signed, to_call_analytics(flags)))
|
Ok((signed, to_call_analytics(flags)))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, Error>>()?;
|
.collect::<Result<Vec<_>, Error>>()?;
|
||||||
|
@ -66,7 +66,7 @@ fn io() -> Tester {
|
|||||||
state_diff: None,
|
state_diff: None,
|
||||||
}));
|
}));
|
||||||
let miner = Arc::new(TestMinerService::default());
|
let miner = Arc::new(TestMinerService::default());
|
||||||
let traces = TracesClient::new(&client, &miner);
|
let traces = TracesClient::new(&client);
|
||||||
let mut io = IoHandler::default();
|
let mut io = IoHandler::default();
|
||||||
io.extend_with(traces.to_delegate());
|
io.extend_with(traces.to_delegate());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user