This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JSON-RPC personal service (follows #582) #583
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6a57e83
json rpc personal service
NikVolf da65761
Merge branch 'secret-store-sync-ready' into json-rpc-personal
NikVolf 4f62e80
name fix
NikVolf 0d01099
moving unlock logics to secret-store itself
NikVolf 4131a60
Merge branch 'master' into json-rpc-personal
NikVolf ae51d99
[ci skip] trailing commas
NikVolf File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2015, 2016 Ethcore (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity 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 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. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Account management (personal) rpc implementation | ||
use std::sync::{Arc, Weak}; | ||
use jsonrpc_core::*; | ||
use v1::traits::Personal; | ||
use util::keys::store::*; | ||
use util::{Bytes, Address}; | ||
use std::sync::RwLock; | ||
|
||
/// Account management (personal) rpc implementation. | ||
pub struct PersonalClient { | ||
secret_store: Weak<SecretStore>, | ||
unlocked_account: Arc<RwLock<Option<Address>>>, | ||
unlocked_secret: Arc<RwLock<Option<Bytes>>>, | ||
} | ||
|
||
impl PersonalClient { | ||
/// Creates new PersonalClient | ||
pub fn new(store: &Arc<SecretStore>) -> Self { | ||
PersonalClient { | ||
secret_store: Arc::downgrade(store), | ||
unlocked_account: Arc::new(RwLock::new(None)), | ||
unlocked_secret: Arc::new(RwLock::new(None)), | ||
} | ||
} | ||
} | ||
|
||
impl Personal for PersonalClient { | ||
fn accounts(&self, _: Params) -> Result<Value, Error> { | ||
let store = take_weak!(self.secret_store); | ||
match store.accounts() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor issue. this function could be less lenient, and return error if there are any input params ;) |
||
Ok(account_list) => { | ||
Ok(Value::Array(account_list.iter() | ||
.map(|&(account, _)| Value::String(format!("{:?}", account))) | ||
.collect::<Vec<Value>>()) | ||
) | ||
} | ||
Err(_) => Err(Error::internal_error()) | ||
} | ||
} | ||
|
||
fn new_account(&self, _: Params) -> Result<Value, Error> { | ||
Err(Error::internal_error()) | ||
} | ||
|
||
fn unlock_account(&self, params: Params) -> Result<Value, Error> { | ||
from_params::<(Address, String, u64)>(params).and_then( | ||
|(account, account_pass, _)|{ | ||
let store = take_weak!(self.secret_store); | ||
let secret_id = match store.account(&account) { | ||
None => { return Ok(Value::Bool(false)); } | ||
Some(id) => id | ||
}; | ||
match store.get(&secret_id, &account_pass) { | ||
Ok(secret) => { | ||
*self.unlocked_account.write().unwrap() = Some(account); | ||
*self.unlocked_secret.write().unwrap() = Some(secret); | ||
Ok(Value::Bool(true)) | ||
}, | ||
Err(_) => { | ||
Ok(Value::Bool(false)) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2015, 2016 Ethcore (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity 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 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. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Personal rpc interface. | ||
use std::sync::Arc; | ||
use jsonrpc_core::*; | ||
|
||
/// Personal rpc interface. | ||
pub trait Personal: Sized + Send + Sync + 'static { | ||
|
||
/// Lists all stored accounts | ||
fn accounts(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } | ||
|
||
/// Creates new account (it becomes new current unlocked account) | ||
fn new_account(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } | ||
|
||
/// Unlocks specified account for use (can only be one unlocked account at one moment) | ||
fn unlock_account(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } | ||
|
||
/// Should be used to convert object to io delegate. | ||
fn to_delegate(self) -> IoDelegate<Self> { | ||
let mut delegate = IoDelegate::new(Arc::new(self)); | ||
delegate.add_method("personal_listAccounts", Personal::accounts); | ||
delegate.add_method("personal_newAccount", Personal::new_account); | ||
delegate.add_method("personal_unlockAccount", Personal::unlock_account); | ||
delegate | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't secret always
H256
?