mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Add a browser-utils crate (#4394)
* Squash * Fix keystore on wasm * Update utils/browser/Cargo.toml Co-Authored-By: Benjamin Kampmann <ben@gnunicorn.org> * export console functions * Use an Option<PathBuf> in keystore instead of cfg flags * Add a KeystoreConfig * Update libp2p * Bump kvdb-web version * Fix cli * Upgrade versions * Update wasm-bindgen stuff Co-authored-by: Benjamin Kampmann <ben.kampmann@googlemail.com>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID};
|
||||
use crate::{SpawnTaskHandle, start_rpc_servers, build_network_future, TransactionPoolAdapter};
|
||||
use crate::status_sinks;
|
||||
use crate::config::{Configuration, DatabaseConfig};
|
||||
use crate::config::{Configuration, DatabaseConfig, KeystoreConfig};
|
||||
use sc_client_api::{
|
||||
self,
|
||||
BlockchainEvents,
|
||||
@@ -165,10 +165,13 @@ fn new_full_parts<TBl, TRtApi, TExecDisp, TCfg, TGen, TCSExt>(
|
||||
TGen: sp_runtime::BuildStorage + serde::Serialize + for<'de> serde::Deserialize<'de>,
|
||||
TCSExt: Extension,
|
||||
{
|
||||
let keystore = Keystore::open(
|
||||
config.keystore_path.clone().ok_or("No basepath configured")?,
|
||||
config.keystore_password.clone()
|
||||
)?;
|
||||
let keystore = match &config.keystore {
|
||||
KeystoreConfig::Path { path, password } => Keystore::open(
|
||||
path.clone().ok_or("No basepath configured")?,
|
||||
password.clone()
|
||||
)?,
|
||||
KeystoreConfig::InMemory => Keystore::new_in_memory()
|
||||
};
|
||||
|
||||
let executor = NativeExecutor::<TExecDisp>::new(
|
||||
config.wasm_method,
|
||||
@@ -286,10 +289,13 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
|
||||
(),
|
||||
TLightBackend<TBl>,
|
||||
>, Error> {
|
||||
let keystore = Keystore::open(
|
||||
config.keystore_path.clone().ok_or("No basepath configured")?,
|
||||
config.keystore_password.clone()
|
||||
)?;
|
||||
let keystore = match &config.keystore {
|
||||
KeystoreConfig::Path { path, password } => Keystore::open(
|
||||
path.clone().ok_or("No basepath configured")?,
|
||||
password.clone()
|
||||
)?,
|
||||
KeystoreConfig::InMemory => Keystore::new_in_memory()
|
||||
};
|
||||
|
||||
let executor = NativeExecutor::<TExecDisp>::new(
|
||||
config.wasm_method,
|
||||
|
||||
@@ -45,8 +45,8 @@ pub struct Configuration<C, G, E = NoExtension> {
|
||||
pub network: NetworkConfiguration,
|
||||
/// Path to the base configuration directory.
|
||||
pub config_dir: Option<PathBuf>,
|
||||
/// Path to key files.
|
||||
pub keystore_path: Option<PathBuf>,
|
||||
/// Configuration for the keystore.
|
||||
pub keystore: KeystoreConfig,
|
||||
/// Configuration for the database.
|
||||
pub database: DatabaseConfig,
|
||||
/// Size of internal state cache in Bytes
|
||||
@@ -92,8 +92,6 @@ pub struct Configuration<C, G, E = NoExtension> {
|
||||
pub force_authoring: bool,
|
||||
/// Disable GRANDPA when running in validator mode
|
||||
pub disable_grandpa: bool,
|
||||
/// Node keystore's password
|
||||
pub keystore_password: Option<Protected<String>>,
|
||||
/// Development key seed.
|
||||
///
|
||||
/// When running in development mode, the seed will be used to generate authority keys by the keystore.
|
||||
@@ -106,6 +104,20 @@ pub struct Configuration<C, G, E = NoExtension> {
|
||||
pub tracing_receiver: sc_tracing::TracingReceiver,
|
||||
}
|
||||
|
||||
/// Configuration of the client keystore.
|
||||
#[derive(Clone)]
|
||||
pub enum KeystoreConfig {
|
||||
/// Keystore at a path on-disk. Recommended for native nodes.
|
||||
Path {
|
||||
/// The path of the keystore. Will panic if no path is specified.
|
||||
path: Option<PathBuf>,
|
||||
/// Node keystore's password.
|
||||
password: Option<Protected<String>>
|
||||
},
|
||||
/// In-memory keystore. Recommended for in-browser nodes.
|
||||
InMemory
|
||||
}
|
||||
|
||||
/// Configuration of the database of the client.
|
||||
#[derive(Clone)]
|
||||
pub enum DatabaseConfig {
|
||||
@@ -138,7 +150,10 @@ impl<C, G, E> Configuration<C, G, E> where
|
||||
roles: Roles::FULL,
|
||||
transaction_pool: Default::default(),
|
||||
network: Default::default(),
|
||||
keystore_path: config_dir.map(|c| c.join("keystore")),
|
||||
keystore: KeystoreConfig::Path {
|
||||
path: config_dir.map(|c| c.join("keystore")),
|
||||
password: None
|
||||
},
|
||||
database: DatabaseConfig::Path {
|
||||
path: Default::default(),
|
||||
cache_size: Default::default(),
|
||||
@@ -161,7 +176,6 @@ impl<C, G, E> Configuration<C, G, E> where
|
||||
sentry_mode: false,
|
||||
force_authoring: false,
|
||||
disable_grandpa: false,
|
||||
keystore_password: None,
|
||||
dev_key_seed: None,
|
||||
tracing_targets: Default::default(),
|
||||
tracing_receiver: Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user