Merge branch 'master' into auth-bft
This commit is contained in:
@@ -28,7 +28,6 @@ use ethstore::random_phrase;
|
||||
use ethsync::{SyncProvider, ManageNetwork};
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::client::{MiningBlockChainClient};
|
||||
use ethcore::ids::BlockID;
|
||||
use ethcore::mode::Mode;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
|
||||
@@ -38,9 +37,11 @@ use v1::types::{
|
||||
Bytes, U256, H160, H256, H512,
|
||||
Peers, Transaction, RpcSettings, Histogram,
|
||||
TransactionStats, LocalTransactionStatus,
|
||||
BlockNumber,
|
||||
};
|
||||
use v1::helpers::{errors, SigningQueue, SignerService, NetworkSettings};
|
||||
use v1::helpers::dispatch::DEFAULT_MAC;
|
||||
use v1::helpers::auto_args::Trailing;
|
||||
|
||||
/// Parity implementation.
|
||||
pub struct ParityClient<C, M, S: ?Sized> where
|
||||
@@ -234,19 +235,20 @@ impl<C, M, S: ?Sized> Parity for ParityClient<C, M, S> where
|
||||
Ok(Brain::new(phrase).generate().unwrap().address().into())
|
||||
}
|
||||
|
||||
fn list_accounts(&self) -> Result<Option<Vec<H160>>, Error> {
|
||||
fn list_accounts(&self, count: u64, after: Option<H160>, block_number: Trailing<BlockNumber>) -> Result<Option<Vec<H160>>, Error> {
|
||||
try!(self.active());
|
||||
|
||||
Ok(take_weak!(self.client)
|
||||
.list_accounts(BlockID::Latest)
|
||||
.list_accounts(block_number.0.into(), after.map(Into::into).as_ref(), count)
|
||||
.map(|a| a.into_iter().map(Into::into).collect()))
|
||||
}
|
||||
|
||||
fn list_storage_keys(&self, _address: H160) -> Result<Option<Vec<H256>>, Error> {
|
||||
fn list_storage_keys(&self, address: H160, count: u64, after: Option<H256>, block_number: Trailing<BlockNumber>) -> Result<Option<Vec<H256>>, Error> {
|
||||
try!(self.active());
|
||||
|
||||
// TODO: implement this
|
||||
Ok(None)
|
||||
Ok(take_weak!(self.client)
|
||||
.list_storage(block_number.0.into(), &address.into(), after.map(Into::into).as_ref(), count)
|
||||
.map(|a| a.into_iter().map(Into::into).collect()))
|
||||
}
|
||||
|
||||
fn encrypt_message(&self, key: H512, phrase: Bytes) -> Result<Bytes, Error> {
|
||||
|
||||
@@ -20,11 +20,11 @@ use std::sync::{Arc, Weak};
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::MiningBlockChainClient;
|
||||
use ethcore::miner::MinerService;
|
||||
use util::Address;
|
||||
use util::{Address, U128, Uint};
|
||||
|
||||
use jsonrpc_core::Error;
|
||||
use v1::traits::Personal;
|
||||
use v1::types::{H160 as RpcH160, H256 as RpcH256, TransactionRequest};
|
||||
use v1::types::{H160 as RpcH160, H256 as RpcH256, U128 as RpcU128, TransactionRequest};
|
||||
use v1::helpers::errors;
|
||||
use v1::helpers::dispatch::{self, sign_and_dispatch};
|
||||
|
||||
@@ -72,15 +72,27 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|
||||
.map_err(|e| errors::account("Could not create account.", e))
|
||||
}
|
||||
|
||||
fn unlock_account(&self, account: RpcH160, account_pass: String, duration: Option<u64>) -> Result<bool, Error> {
|
||||
fn unlock_account(&self, account: RpcH160, account_pass: String, duration: Option<RpcU128>) -> Result<bool, Error> {
|
||||
try!(self.active());
|
||||
let account: Address = account.into();
|
||||
let store = take_weak!(self.accounts);
|
||||
let duration = match duration {
|
||||
None => None,
|
||||
Some(duration) => {
|
||||
let duration: U128 = duration.into();
|
||||
let v = duration.low_u64() as u32;
|
||||
if duration != v.into() {
|
||||
return Err(errors::invalid_params("Duration", "Invalid Number"));
|
||||
} else {
|
||||
Some(v)
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let r = match (self.allow_perm_unlock, duration) {
|
||||
(false, _) => store.unlock_account_temporarily(account, account_pass),
|
||||
(true, Some(0)) => store.unlock_account_permanently(account, account_pass),
|
||||
(true, Some(d)) => store.unlock_account_timed(account, account_pass, d as u32 * 1000),
|
||||
(true, Some(d)) => store.unlock_account_timed(account, account_pass, d * 1000),
|
||||
(true, None) => store.unlock_account_timed(account, account_pass, 300_000),
|
||||
};
|
||||
match r {
|
||||
|
||||
@@ -164,3 +164,45 @@ fn sign_and_send_transaction() {
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request.as_ref()), Some(response));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_unlock_account_temporarily() {
|
||||
let tester = setup();
|
||||
let address = tester.accounts.new_account("password123").unwrap();
|
||||
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "personal_unlockAccount",
|
||||
"params": [
|
||||
""#.to_owned() + &format!("0x{:?}", address) + r#"",
|
||||
"password123",
|
||||
"0x100"
|
||||
],
|
||||
"id": 1
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
|
||||
assert!(tester.accounts.sign(address, None, Default::default()).is_ok(), "Should unlock account.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_unlock_account_permanently() {
|
||||
let tester = setup();
|
||||
let address = tester.accounts.new_account("password123").unwrap();
|
||||
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "personal_unlockAccount",
|
||||
"params": [
|
||||
""#.to_owned() + &format!("0x{:?}", address) + r#"",
|
||||
"password123",
|
||||
null
|
||||
],
|
||||
"id": 1
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
assert!(tester.accounts.sign(address, None, Default::default()).is_ok(), "Should unlock account.");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
use jsonrpc_core::Error;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use v1::helpers::auto_args::Wrap;
|
||||
use v1::helpers::auto_args::{Wrap, Trailing};
|
||||
use v1::types::{
|
||||
H160, H256, H512, U256, Bytes,
|
||||
Peers, Transaction, RpcSettings, Histogram,
|
||||
TransactionStats, LocalTransactionStatus,
|
||||
BlockNumber
|
||||
};
|
||||
|
||||
build_rpc_trait! {
|
||||
@@ -103,12 +104,12 @@ build_rpc_trait! {
|
||||
|
||||
/// Returns all addresses if Fat DB is enabled (`--fat-db`), or null if not.
|
||||
#[rpc(name = "parity_listAccounts")]
|
||||
fn list_accounts(&self) -> Result<Option<Vec<H160>>, Error>;
|
||||
fn list_accounts(&self, u64, Option<H160>, Trailing<BlockNumber>) -> Result<Option<Vec<H160>>, Error>;
|
||||
|
||||
/// Returns all storage keys of the given address (first parameter) if Fat DB is enabled (`--fat-db`),
|
||||
/// or null if not.
|
||||
#[rpc(name = "parity_listStorageKeys")]
|
||||
fn list_storage_keys(&self, H160) -> Result<Option<Vec<H256>>, Error>;
|
||||
fn list_storage_keys(&self, H160, u64, Option<H256>, Trailing<BlockNumber>) -> Result<Option<Vec<H256>>, Error>;
|
||||
|
||||
/// Encrypt some data with a public key under ECIES.
|
||||
/// First parameter is the 512-byte destination public key, second is the message.
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
use jsonrpc_core::Error;
|
||||
|
||||
use v1::helpers::auto_args::Wrap;
|
||||
use v1::types::{H160, H256, TransactionRequest};
|
||||
use v1::types::{U128, H160, H256, TransactionRequest};
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Personal rpc interface. Safe (read-only) functions.
|
||||
@@ -34,7 +34,7 @@ build_rpc_trait! {
|
||||
|
||||
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
||||
#[rpc(name = "personal_unlockAccount")]
|
||||
fn unlock_account(&self, H160, String, Option<u64>) -> Result<bool, Error>;
|
||||
fn unlock_account(&self, H160, String, Option<U128>) -> Result<bool, Error>;
|
||||
|
||||
/// Sends transaction and signs it in single call. The account is not unlocked in such case.
|
||||
#[rpc(name = "personal_signAndSendTransaction")]
|
||||
|
||||
@@ -19,6 +19,7 @@ use v1::types::{Bytes, H160, U256};
|
||||
|
||||
/// Call request
|
||||
#[derive(Debug, Default, PartialEq, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CallRequest {
|
||||
/// From
|
||||
pub from: Option<H160>,
|
||||
|
||||
@@ -137,6 +137,7 @@ impl From<helpers::ConfirmationPayload> for ConfirmationPayload {
|
||||
|
||||
/// Possible modifications to the confirmed transaction sent by `Trusted Signer`
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TransactionModification {
|
||||
/// Modified gas price
|
||||
#[serde(rename="gasPrice")]
|
||||
|
||||
@@ -124,8 +124,8 @@ impl Serialize for FilterChanges {
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use std::str::FromStr;
|
||||
use util::hash::*;
|
||||
use super::*;
|
||||
use util::hash::H256;
|
||||
use super::{VariadicValue, Topic, Filter};
|
||||
use v1::types::BlockNumber;
|
||||
use ethcore::filter::Filter as EthFilter;
|
||||
use ethcore::client::BlockID;
|
||||
|
||||
@@ -21,6 +21,7 @@ use util::stats;
|
||||
|
||||
/// Values of RPC settings.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Histogram {
|
||||
/// Gas prices for bucket edges.
|
||||
#[serde(rename="bucketBounds")]
|
||||
|
||||
@@ -50,6 +50,6 @@ pub use self::receipt::Receipt;
|
||||
pub use self::rpc_settings::RpcSettings;
|
||||
pub use self::trace::{LocalizedTrace, TraceResults};
|
||||
pub use self::trace_filter::TraceFilter;
|
||||
pub use self::uint::U256;
|
||||
pub use self::uint::{U128, U256};
|
||||
pub use self::work::Work;
|
||||
pub use self::histogram::Histogram;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
/// Values of RPC settings.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RpcSettings {
|
||||
/// Whether RPC is enabled.
|
||||
pub enabled: bool,
|
||||
@@ -25,4 +26,4 @@ pub struct RpcSettings {
|
||||
pub interface: String,
|
||||
/// The port being listened on.
|
||||
pub port: u64,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use v1::types::{BlockNumber, H160};
|
||||
|
||||
/// Trace filter
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TraceFilter {
|
||||
/// From block
|
||||
#[serde(rename="fromBlock")]
|
||||
|
||||
@@ -21,6 +21,7 @@ use v1::helpers;
|
||||
|
||||
/// Transaction request coming from RPC
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TransactionRequest {
|
||||
/// Sender
|
||||
pub from: H160,
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::cmp;
|
||||
use std::str::FromStr;
|
||||
use rustc_serialize::hex::ToHex;
|
||||
use serde;
|
||||
use util::{U256 as EthU256, Uint};
|
||||
use util::{U256 as EthU256, U128 as EthU128, Uint};
|
||||
|
||||
macro_rules! impl_uint {
|
||||
($name: ident, $other: ident, $size: expr) => {
|
||||
@@ -98,6 +98,7 @@ macro_rules! impl_uint {
|
||||
}
|
||||
}
|
||||
|
||||
impl_uint!(U128, EthU128, 2);
|
||||
impl_uint!(U256, EthU256, 4);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user