mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
move fetch metadata to a separate crate subxt_utils_fetchmetadata (#1829)
* macros: feature-gate jsonrpsee/fetch metadata url * make CI happy * Update codegen/src/error.rs * extract `fetch-metdata` to separate crate * add missing license headers * introduce subxt-utils crate * add missing files * codegen: remove unused hex crate * fix test build * move subxt_utils -> subxt_utils_fetchmetadata * cargo fmt * runtime-path -> runtime-metadata-path * Update utils/fetch-metadata/src/lib.rs
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Copyright 2019-2024 Parity Technologies (UK) Ltd.
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
//! Subxt utils fetch metadata.
|
||||
|
||||
// Internal helper macros
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod error;
|
||||
|
||||
cfg_fetch_from_url! {
|
||||
mod url;
|
||||
pub use url::{from_url, from_url_blocking, MetadataVersion, Url};
|
||||
}
|
||||
|
||||
pub use error::Error;
|
||||
|
||||
/// Fetch metadata from a file in a blocking manner.
|
||||
pub fn from_file_blocking(path: &std::path::Path) -> Result<Vec<u8>, error::Error> {
|
||||
use std::io::Read;
|
||||
|
||||
let to_err = |err| error::Error::Io(path.to_string_lossy().into(), err);
|
||||
let mut file = std::fs::File::open(path).map_err(to_err)?;
|
||||
let mut bytes = Vec::new();
|
||||
file.read_to_end(&mut bytes).map_err(to_err)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
Reference in New Issue
Block a user