mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
Use pathbuf for remote externalities (#8480)
* Combine SnapshotConfig string fields name and directory into single PathBuf field named path * Update Cargo.lock * fix test build failure
This commit is contained in:
Generated
-16
@@ -4635,22 +4635,6 @@ dependencies = [
|
||||
"sp-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pallet-assets-freezer"
|
||||
version = "3.0.0"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
"frame-system",
|
||||
"pallet-assets",
|
||||
"parity-scale-codec 2.0.1",
|
||||
"serde",
|
||||
"sp-core",
|
||||
"sp-io",
|
||||
"sp-runtime",
|
||||
"sp-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pallet-atomic-swap"
|
||||
version = "3.0.0"
|
||||
|
||||
@@ -181,23 +181,19 @@ impl<B: BlockT> OnlineConfig<B> {
|
||||
/// Configuration of the state snapshot.
|
||||
#[derive(Clone)]
|
||||
pub struct SnapshotConfig {
|
||||
// TODO: I could mix these two into one filed, but I think separate is better bc one can be
|
||||
// configurable while one not.
|
||||
/// File name.
|
||||
pub name: String,
|
||||
/// Base directory.
|
||||
pub directory: String,
|
||||
/// The path to the snapshot file.
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
impl SnapshotConfig {
|
||||
pub fn new<P: Into<PathBuf>>(path: P) -> Self {
|
||||
Self { path: path.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SnapshotConfig {
|
||||
fn default() -> Self {
|
||||
Self { name: "SNAPSHOT".into(), directory: ".".into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapshotConfig {
|
||||
fn path(&self) -> PathBuf {
|
||||
Path::new(&self.directory).join(self.name.clone())
|
||||
Self { path: Path::new("SNAPSHOT").into() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,12 +315,12 @@ impl<B: BlockT> Builder<B> {
|
||||
|
||||
async fn pre_build(mut self) -> Result<Vec<KeyPair>, &'static str> {
|
||||
let mut base_kv = match self.mode.clone() {
|
||||
Mode::Offline(config) => self.load_state_snapshot(&config.state_snapshot.path())?,
|
||||
Mode::Offline(config) => self.load_state_snapshot(&config.state_snapshot.path)?,
|
||||
Mode::Online(config) => {
|
||||
self.init_remote_client().await?;
|
||||
let kp = self.load_remote().await?;
|
||||
if let Some(c) = config.state_snapshot {
|
||||
self.save_state_snapshot(&kp, &c.path())?;
|
||||
self.save_state_snapshot(&kp, &c.path)?;
|
||||
}
|
||||
kp
|
||||
}
|
||||
@@ -399,7 +395,7 @@ mod tests {
|
||||
init_logger();
|
||||
Builder::<Block>::new()
|
||||
.mode(Mode::Offline(OfflineConfig {
|
||||
state_snapshot: SnapshotConfig { name: "test_data/proxy_test".into(), ..Default::default() },
|
||||
state_snapshot: SnapshotConfig { path: "test_data/proxy_test".into() },
|
||||
}))
|
||||
.build()
|
||||
.await
|
||||
|
||||
@@ -67,15 +67,14 @@ pub struct TryRuntimeCmd {
|
||||
pub enum State {
|
||||
/// Use a state snapshot as state to run the migration.
|
||||
Snap {
|
||||
#[structopt(flatten)]
|
||||
snapshot_path: SnapshotPath,
|
||||
snapshot_path: PathBuf,
|
||||
},
|
||||
|
||||
/// Use a live chain to run the migration.
|
||||
Live {
|
||||
/// An optional state snapshot file to WRITE to. Not written if set to `None`.
|
||||
#[structopt(short, long)]
|
||||
snapshot_path: Option<SnapshotPath>,
|
||||
snapshot_path: Option<PathBuf>,
|
||||
|
||||
/// The block hash at which to connect.
|
||||
/// Will be latest finalized head if not provided.
|
||||
@@ -118,31 +117,6 @@ fn parse_url(s: &str) -> Result<String, &'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, structopt::StructOpt)]
|
||||
pub struct SnapshotPath {
|
||||
/// The directory of the state snapshot.
|
||||
#[structopt(short, long, default_value = ".")]
|
||||
directory: String,
|
||||
|
||||
/// The file name of the state snapshot.
|
||||
#[structopt(default_value = "SNAPSHOT")]
|
||||
file_name: String,
|
||||
}
|
||||
|
||||
impl FromStr for SnapshotPath {
|
||||
type Err = &'static str;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let p: PathBuf = s.parse().map_err(|_| "invalid path")?;
|
||||
let parent = p.parent();
|
||||
let file_name = p.file_name();
|
||||
|
||||
file_name.and_then(|file_name| Some(Self {
|
||||
directory: parent.map(|p| p.to_string_lossy().into()).unwrap_or(".".to_string()),
|
||||
file_name: file_name.to_string_lossy().into()
|
||||
})).ok_or("invalid path")
|
||||
}
|
||||
}
|
||||
|
||||
impl TryRuntimeCmd {
|
||||
pub async fn run<B, ExecDispatch>(&self, config: Configuration) -> sc_cli::Result<()>
|
||||
where
|
||||
@@ -182,12 +156,8 @@ impl TryRuntimeCmd {
|
||||
use remote_externalities::{Builder, Mode, SnapshotConfig, OfflineConfig, OnlineConfig};
|
||||
let builder = match &self.state {
|
||||
State::Snap { snapshot_path } => {
|
||||
let SnapshotPath { directory, file_name } = snapshot_path;
|
||||
Builder::<B>::new().mode(Mode::Offline(OfflineConfig {
|
||||
state_snapshot: SnapshotConfig {
|
||||
name: file_name.into(),
|
||||
directory: directory.into(),
|
||||
},
|
||||
state_snapshot: SnapshotConfig::new(snapshot_path),
|
||||
}))
|
||||
},
|
||||
State::Live {
|
||||
@@ -197,10 +167,7 @@ impl TryRuntimeCmd {
|
||||
modules
|
||||
} => Builder::<B>::new().mode(Mode::Online(OnlineConfig {
|
||||
uri: url.into(),
|
||||
state_snapshot: snapshot_path.as_ref().map(|c| SnapshotConfig {
|
||||
name: c.file_name.clone(),
|
||||
directory: c.directory.clone(),
|
||||
}),
|
||||
state_snapshot: snapshot_path.as_ref().map(SnapshotConfig::new),
|
||||
modules: modules.clone().unwrap_or_default(),
|
||||
at: match block_at {
|
||||
Some(b) => Some(b.parse().map_err(|e| format!("Could not parse hash: {:?}", e))?),
|
||||
|
||||
Reference in New Issue
Block a user