Polishing Actually enable fat db pr (#1974) (#2048)

* Actually enable fat db, and do RPCs for it.

* Implement HashDB traits for AccountDB.

* user defaults

* finished user defaults

* user defaults are network-dependent

* added tests for newly added functions, logger is initialized first

* dir cleanup in progress

* user_file is placed next to snapshots

* fixing requested change
This commit is contained in:
Marek Kotewicz
2016-10-03 11:13:10 +02:00
committed by Gav Wood
parent 0dcdaa7a2a
commit 06fe768ac2
20 changed files with 188 additions and 34 deletions

View File

@@ -29,6 +29,7 @@ use ethstore::random_phrase;
use ethsync::{SyncProvider, ManageNetwork};
use ethcore::miner::MinerService;
use ethcore::client::{MiningBlockChainClient};
use ethcore::ids::BlockID;
use jsonrpc_core::{from_params, to_value, Value, Error, Params, Ready};
use v1::traits::Ethcore;
@@ -251,6 +252,24 @@ impl<C, M, S: ?Sized, F> Ethcore for EthcoreClient<C, M, S, F> where
)
}
fn list_accounts(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
try!(expect_no_params(params));
take_weak!(self.client)
.list_accounts(BlockID::Latest)
.map(|a| Ok(to_value(&a.into_iter().map(Into::into).collect::<Vec<H160>>())))
.unwrap_or(Ok(Value::Null))
}
fn list_storage_keys(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
from_params::<(H160,)>(params).and_then(|(_addr,)|
Ok(Value::Null)
)
}
fn encrypt_message(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
from_params::<(H512, Bytes)>(params).and_then(|(key, phrase)| {

View File

@@ -76,6 +76,14 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
/// Returns the value of the registrar for this network.
fn registry_address(&self, _: Params) -> Result<Value, Error>;
/// Returns all addresses if Fat DB is enabled (`--fat-db`), or null if not.
/// Takes no parameters.
fn list_accounts(&self, _: Params) -> Result<Value, Error>;
/// Returns all storage keys of the given address (first parameter) if Fat DB is enabled (`--fat-db`),
/// or null if not.
fn list_storage_keys(&self, _: Params) -> Result<Value, Error>;
/// Encrypt some data with a public key under ECIES.
/// First parameter is the 512-byte destination public key, second is the message.
fn encrypt_message(&self, _: Params) -> Result<Value, Error>;
@@ -108,6 +116,8 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
delegate.add_method("ethcore_generateSecretPhrase", Ethcore::generate_secret_phrase);
delegate.add_method("ethcore_phraseToAddress", Ethcore::phrase_to_address);
delegate.add_method("ethcore_registryAddress", Ethcore::registry_address);
delegate.add_method("ethcore_listAccounts", Ethcore::list_accounts);
delegate.add_method("ethcore_listStorageKeys", Ethcore::list_storage_keys);
delegate.add_method("ethcore_encryptMessage", Ethcore::encrypt_message);
delegate.add_method("ethcore_pendingTransactions", Ethcore::pending_transactions);
delegate.add_async_method("ethcore_hashContent", Ethcore::hash_content);