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

Remove all dapp permissions related settings #9120

Merged
merged 11 commits into from
Aug 7, 2018
5 changes: 2 additions & 3 deletions rpc/src/http_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait HttpMetaExtractor: Send + Sync + 'static {
/// Type of Metadata
type Metadata: jsonrpc_core::Metadata;
/// Extracts metadata from given params.
fn read_metadata(&self, origin: Option<String>, user_agent: Option<String>, dapps_origin: Option<String>) -> Self::Metadata;
fn read_metadata(&self, origin: Option<String>, user_agent: Option<String>) -> Self::Metadata;
}

pub struct MetaExtractor<T> {
Expand All @@ -49,7 +49,6 @@ impl<M, T> http::MetaExtractor<M> for MetaExtractor<T> where

let origin = as_string(req.headers().get_raw("origin"));
let user_agent = as_string(req.headers().get_raw("user-agent"));
let dapps_origin = as_string(req.headers().get_raw("x-parity-origin"));
self.extractor.read_metadata(origin, user_agent, dapps_origin)
self.extractor.read_metadata(origin, user_agent)
}
}
10 changes: 5 additions & 5 deletions rpc/src/v1/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub struct RpcExtractor;
impl HttpMetaExtractor for RpcExtractor {
type Metadata = Metadata;

fn read_metadata(&self, _origin: Option<String>, user_agent: Option<String>, _dapps_origin: Option<String>) -> Metadata {
fn read_metadata(&self, origin: Option<String>, user_agent: Option<String>) -> Metadata {
Metadata {
origin: match user_agent {
origin: match user_agent.or(origin) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO should be other way around, Origin provides more info than UserAgent. Maybe best just do:

let service = format!("{} / {}", origin.unwrap_or("unknown origin"), user_agent.unwrap_or("unknown agent"));

?

Some(service) => Origin::Rpc(service.into()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be good to actually use the Origin as well (if available)

None => Origin::Rpc("unknown".into()),
},
Expand Down Expand Up @@ -250,9 +250,9 @@ mod tests {
let extractor = RpcExtractor;

// when
let meta1 = extractor.read_metadata(None, None, None);
let meta2 = extractor.read_metadata(None, Some("http://parity.io".to_owned()), None);
let meta3 = extractor.read_metadata(None, Some("http://parity.io".to_owned()), Some("ignored".into()));
let meta1 = extractor.read_metadata(None, None);
let meta2 = extractor.read_metadata(None, Some("http://parity.io".to_owned()));
let meta3 = extractor.read_metadata(None, Some("http://parity.io".to_owned()));

// then
assert_eq!(meta1.origin, Origin::Rpc("unknown".into()));
Expand Down
10 changes: 3 additions & 7 deletions rpc/src/v1/helpers/fake_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@

use transaction::{Transaction, SignedTransaction, Action};

use ethereum_types::U256;
use jsonrpc_core::Error;
use v1::helpers::CallRequest;

pub fn sign_call(request: CallRequest, gas_cap: bool) -> Result<SignedTransaction, Error> {
let max_gas = 50_000_000.into();
pub fn sign_call(request: CallRequest) -> Result<SignedTransaction, Error> {
let max_gas = U256::from(50_000_000);
let gas = match request.gas {
Some(gas) if gas_cap && gas > max_gas => {
warn!("Gas limit capped to {} (from {})", max_gas, gas);
max_gas
}
Some(gas) => gas,
None if gas_cap => max_gas,
None => max_gas * 10,
};
let from = request.from.unwrap_or(0.into());
Expand Down
12 changes: 6 additions & 6 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
}
}

fn author(&self, _meta: Metadata) -> Result<RpcH160> {
fn author(&self) -> Result<RpcH160> {
let mut miner = self.miner.authoring_params().author;
if miner == 0.into() {
miner = self.accounts.accounts().ok().and_then(|a| a.get(0).cloned()).unwrap_or_default();
Expand All @@ -523,7 +523,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
Ok(RpcU256::from(default_gas_price(&*self.client, &*self.miner, self.options.gas_price_percentile)))
}

fn accounts(&self, _meta: Metadata) -> Result<Vec<RpcH160>> {
fn accounts(&self) -> Result<Vec<RpcH160>> {
let accounts = self.accounts.accounts()
.map_err(|e| errors::account("Could not fetch accounts.", e))?;
Ok(accounts.into_iter().map(Into::into).collect())
Expand Down Expand Up @@ -826,9 +826,9 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
self.send_raw_transaction(raw)
}

fn call(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
fn call(&self, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
let request = CallRequest::into(request);
let signed = try_bf!(fake_sign::sign_call(request, meta.is_dapp()));
let signed = try_bf!(fake_sign::sign_call(request));

let num = num.unwrap_or_default();

Expand Down Expand Up @@ -866,9 +866,9 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient<
))
}

fn estimate_gas(&self, meta: Self::Metadata, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
let request = CallRequest::into(request);
let signed = try_bf!(fake_sign::sign_call(request, meta.is_dapp()));
let signed = try_bf!(fake_sign::sign_call(request));
let num = num.unwrap_or_default();

let (state, header) = if num == BlockNumber::Pending {
Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/impls/light/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}
}

fn author(&self, _meta: Self::Metadata) -> Result<RpcH160> {
fn author(&self) -> Result<RpcH160> {
Ok(Default::default())
}

Expand All @@ -271,7 +271,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
.unwrap_or_else(Default::default))
}

fn accounts(&self, _meta: Metadata) -> Result<Vec<RpcH160>> {
fn accounts(&self) -> Result<Vec<RpcH160>> {
self.accounts.accounts()
.map_err(|e| errors::account("Could not fetch accounts.", e))
.map(|accs| accs.into_iter().map(Into::<RpcH160>::into).collect())
Expand Down Expand Up @@ -394,7 +394,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
self.send_raw_transaction(raw)
}

fn call(&self, _meta: Self::Metadata, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
fn call(&self, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<Bytes> {
Box::new(self.fetcher().proved_execution(req, num).and_then(|res| {
match res {
Ok(exec) => Ok(exec.output.into()),
Expand All @@ -403,7 +403,7 @@ impl<T: LightChainClient + 'static> Eth for EthClient<T> {
}))
}

fn estimate_gas(&self, _meta: Self::Metadata, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
fn estimate_gas(&self, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<RpcU256> {
// TODO: binary chop for more accurate estimates.
Box::new(self.fetcher().proved_execution(req, num).and_then(|res| {
match res {
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/impls/light/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Parity for ParityClient {
Ok(store.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))?)
}

fn default_account(&self, _meta: Self::Metadata) -> Result<H160> {
fn default_account(&self) -> Result<H160> {
Ok(self.accounts
.accounts()
.ok()
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Parity for ParityClient {
ipfs::cid(content)
}

fn call(&self, _meta: Self::Metadata, _requests: Vec<CallRequest>, _block: Trailing<BlockNumber>) -> Result<Vec<Bytes>> {
fn call(&self, _requests: Vec<CallRequest>, _block: Trailing<BlockNumber>) -> Result<Vec<Bytes>> {
Err(errors::light_unimplemented(None))
}
}
4 changes: 2 additions & 2 deletions rpc/src/v1/impls/light/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ impl Traces for TracesClient {
Err(errors::light_unimplemented(None))
}

fn call(&self, _meta: Self::Metadata, _request: CallRequest, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> Result<TraceResults> {
fn call(&self, _request: CallRequest, _flags: TraceOptions, _block: Trailing<BlockNumber>) -> Result<TraceResults> {
Err(errors::light_unimplemented(None))
}

fn call_many(&self, _meta: Self::Metadata, _request: Vec<(CallRequest, TraceOptions)>, _block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>> {
fn call_many(&self, _request: Vec<(CallRequest, TraceOptions)>, _block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>> {
Err(errors::light_unimplemented(None))
}

Expand Down
6 changes: 3 additions & 3 deletions rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
self.accounts.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e))
}

fn default_account(&self, _meta: Self::Metadata) -> Result<H160> {
fn default_account(&self) -> Result<H160> {
Ok(self.accounts.default_account()
.map(Into::into)
.ok()
Expand Down Expand Up @@ -420,11 +420,11 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
ipfs::cid(content)
}

fn call(&self, meta: Self::Metadata, requests: Vec<CallRequest>, num: Trailing<BlockNumber>) -> Result<Vec<Bytes>> {
fn call(&self, requests: Vec<CallRequest>, num: Trailing<BlockNumber>) -> Result<Vec<Bytes>> {
let requests = requests
.into_iter()
.map(|request| Ok((
fake_sign::sign_call(request.into(), meta.is_dapp())?,
fake_sign::sign_call(request.into())?,
Default::default()
)))
.collect::<Result<Vec<_>>>()?;
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/v1/impls/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ impl Private for PrivateClient {
})
}

fn private_call(&self, meta: Self::Metadata, block_number: BlockNumber, request: CallRequest) -> Result<Bytes, Error> {
fn private_call(&self, 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 signed = fake_sign::sign_call(request)?;
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())
Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/impls/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ impl<C, S> Traces for TracesClient<C> where
.map(LocalizedTrace::from))
}

fn call(&self, meta: Self::Metadata, request: CallRequest, flags: TraceOptions, block: Trailing<BlockNumber>) -> Result<TraceResults> {
fn call(&self, request: CallRequest, flags: TraceOptions, block: Trailing<BlockNumber>) -> Result<TraceResults> {
let block = block.unwrap_or_default();

let request = CallRequest::into(request);
let signed = fake_sign::sign_call(request, meta.is_dapp())?;
let signed = fake_sign::sign_call(request)?;

let id = match block {
BlockNumber::Num(num) => BlockId::Number(num),
Expand All @@ -109,13 +109,13 @@ impl<C, S> Traces for TracesClient<C> where
.map_err(errors::call)
}

fn call_many(&self, meta: Self::Metadata, requests: Vec<(CallRequest, TraceOptions)>, block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>> {
fn call_many(&self, requests: Vec<(CallRequest, TraceOptions)>, block: Trailing<BlockNumber>) -> Result<Vec<TraceResults>> {
let block = block.unwrap_or_default();

let requests = requests.into_iter()
.map(|(request, flags)| {
let request = CallRequest::into(request);
let signed = fake_sign::sign_call(request, meta.is_dapp())?;
let signed = fake_sign::sign_call(request)?;
Ok((signed, to_call_analytics(flags)))
})
.collect::<Result<Vec<_>>>()?;
Expand Down
7 changes: 0 additions & 7 deletions rpc/src/v1/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ pub struct Metadata {
pub session: Option<Arc<Session>>,
}

impl Metadata {
/// Returns true if the request originates from a Dapp.
pub fn is_dapp(&self) -> bool {
false
}
}

impl jsonrpc_core::Metadata for Metadata {}
impl PubSubMetadata for Metadata {
fn session(&self) -> Option<Arc<Session>> {
Expand Down
16 changes: 8 additions & 8 deletions rpc/src/v1/traits/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ build_rpc_trait! {
fn hashrate(&self) -> Result<U256>;

/// Returns block author.
#[rpc(meta, name = "eth_coinbase")]
fn author(&self, Self::Metadata) -> Result<H160>;
#[rpc(name = "eth_coinbase")]
fn author(&self) -> Result<H160>;

/// Returns true if client is actively mining new blocks.
#[rpc(name = "eth_mining")]
Expand All @@ -52,8 +52,8 @@ build_rpc_trait! {
fn gas_price(&self) -> Result<U256>;

/// Returns accounts list.
#[rpc(meta, name = "eth_accounts")]
fn accounts(&self, Self::Metadata) -> Result<Vec<H160>>;
#[rpc(name = "eth_accounts")]
fn accounts(&self) -> Result<Vec<H160>>;

/// Returns highest block number.
#[rpc(name = "eth_blockNumber")]
Expand Down Expand Up @@ -108,12 +108,12 @@ build_rpc_trait! {
fn submit_transaction(&self, Bytes) -> Result<H256>;

/// Call contract, returning the output data.
#[rpc(meta, name = "eth_call")]
fn call(&self, Self::Metadata, CallRequest, Trailing<BlockNumber>) -> BoxFuture<Bytes>;
#[rpc(name = "eth_call")]
fn call(&self, CallRequest, Trailing<BlockNumber>) -> BoxFuture<Bytes>;

/// Estimate gas needed for execution of given contract.
#[rpc(meta, name = "eth_estimateGas")]
fn estimate_gas(&self, Self::Metadata, CallRequest, Trailing<BlockNumber>) -> BoxFuture<U256>;
#[rpc(name = "eth_estimateGas")]
fn estimate_gas(&self, CallRequest, Trailing<BlockNumber>) -> BoxFuture<U256>;

/// Get transaction by its hash.
#[rpc(name = "eth_getTransactionByHash")]
Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/traits/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ build_rpc_trait! {
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>>;

/// Returns default account for dapp.
#[rpc(meta, name = "parity_defaultAccount")]
fn default_account(&self, Self::Metadata) -> Result<H160>;
#[rpc(name = "parity_defaultAccount")]
fn default_account(&self) -> Result<H160>;

/// Returns current transactions limit.
#[rpc(name = "parity_transactionsLimit")]
Expand Down Expand Up @@ -216,7 +216,7 @@ build_rpc_trait! {
fn ipfs_cid(&self, Bytes) -> Result<String>;

/// Call contract, returning the output data.
#[rpc(meta, name = "parity_call")]
fn call(&self, Self::Metadata, Vec<CallRequest>, Trailing<BlockNumber>) -> Result<Vec<Bytes>>;
#[rpc(name = "parity_call")]
fn call(&self, Vec<CallRequest>, Trailing<BlockNumber>) -> Result<Vec<Bytes>>;
}
}
4 changes: 2 additions & 2 deletions rpc/src/v1/traits/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ build_rpc_trait! {
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>;
#[rpc(name = "private_call")]
fn private_call(&self, BlockNumber, CallRequest) -> Result<Bytes, Error>;

/// Retrieve the id of the key associated with the contract
#[rpc(name = "private_contractKey")]
Expand Down
8 changes: 4 additions & 4 deletions rpc/src/v1/traits/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ build_rpc_trait! {
fn block_traces(&self, BlockNumber) -> Result<Option<Vec<LocalizedTrace>>>;

/// Executes the given call and returns a number of possible traces for it.
#[rpc(meta, name = "trace_call")]
fn call(&self, Self::Metadata, CallRequest, TraceOptions, Trailing<BlockNumber>) -> Result<TraceResults>;
#[rpc(name = "trace_call")]
fn call(&self, CallRequest, TraceOptions, Trailing<BlockNumber>) -> Result<TraceResults>;

/// Executes all given calls and returns a number of possible traces for each of it.
#[rpc(meta, name = "trace_callMany")]
fn call_many(&self, Self::Metadata, Vec<(CallRequest, TraceOptions)>, Trailing<BlockNumber>) -> Result<Vec<TraceResults>>;
#[rpc(name = "trace_callMany")]
fn call_many(&self, Vec<(CallRequest, TraceOptions)>, Trailing<BlockNumber>) -> Result<Vec<TraceResults>>;

/// Executes the given raw transaction and returns a number of possible traces for it.
#[rpc(name = "trace_rawTransaction")]
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/types/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl fmt::Display for Origin {
Origin::Rpc(ref origin) => write!(f, "{} via RPC", origin),
Origin::Ipc(ref session) => write!(f, "IPC (session: {})", session),
Origin::Ws { ref session } => write!(f, "WebSocket (session: {})", session),
Origin::Signer { ref session } => write!(f, "Signer (session: {})", session),
Origin::Signer { ref session } => write!(f, "Secure Session (session: {})", session),
Origin::CApi => write!(f, "C API"),
Origin::Unknown => write!(f, "unknown origin"),
}
Expand Down