mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 16:01:08 +00:00
Make system properties an arbitrary JSON object, plus CI fixes (#349)
* Make system properties an arbitrary JSON object * Add comment * Make timestamp test more reliable * Fmt * Update src/client.rs Co-authored-by: David <dvdplm@gmail.com> * Update src/client.rs Co-authored-by: David <dvdplm@gmail.com> * Fix clippy errors and warnings * Fix tests Co-authored-by: David <dvdplm@gmail.com>
This commit is contained in:
+2
-2
@@ -120,7 +120,7 @@ fn main() -> color_eyre::Result<()> {
|
|||||||
});
|
});
|
||||||
let (_, bytes) = fetch_metadata(&url)?;
|
let (_, bytes) = fetch_metadata(&url)?;
|
||||||
codegen(&mut &bytes[..])?;
|
codegen(&mut &bytes[..])?;
|
||||||
return Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ fn fetch_metadata(url: &url::Url) -> color_eyre::Result<(String, Vec<u8>)> {
|
|||||||
let hex_data = json["result"]
|
let hex_data = json["result"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.map(ToString::to_string)
|
.map(ToString::to_string)
|
||||||
.ok_or(eyre::eyre!("metadata result field should be a string"))?;
|
.ok_or_else(|| eyre::eyre!("metadata result field should be a string"))?;
|
||||||
let bytes = hex::decode(hex_data.trim_start_matches("0x"))?;
|
let bytes = hex::decode(hex_data.trim_start_matches("0x"))?;
|
||||||
|
|
||||||
Ok((hex_data, bytes))
|
Ok((hex_data, bytes))
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ impl ItemMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum Item {
|
pub enum Item {
|
||||||
Rust(syn::Item),
|
Rust(syn::Item),
|
||||||
Subxt(SubxtItem),
|
Subxt(SubxtItem),
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use scale_info::{
|
|||||||
TypeInfo,
|
TypeInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MOD_PATH: &'static [&'static str] = &["subxt_codegen", "types", "tests"];
|
const MOD_PATH: &[&str] = &["subxt_codegen", "types", "tests"];
|
||||||
|
|
||||||
fn get_mod<'a>(module: &'a Module, path_segs: &[&'static str]) -> Option<&'a Module<'a>> {
|
fn get_mod<'a>(module: &'a Module, path_segs: &[&'static str]) -> Option<&'a Module<'a>> {
|
||||||
let (mod_name, rest) = path_segs.split_first()?;
|
let (mod_name, rest) = path_segs.split_first()?;
|
||||||
@@ -790,7 +790,7 @@ fn generics_with_alias_adds_phantom_data_marker() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn modules() {
|
fn modules() {
|
||||||
mod modules {
|
mod m {
|
||||||
pub mod a {
|
pub mod a {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[derive(scale_info::TypeInfo)]
|
#[derive(scale_info::TypeInfo)]
|
||||||
@@ -815,7 +815,7 @@ fn modules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut registry = Registry::new();
|
let mut registry = Registry::new();
|
||||||
registry.register_type(&meta_type::<modules::c::Foo>());
|
registry.register_type(&meta_type::<m::c::Foo>());
|
||||||
let portable_types: PortableRegistry = registry.into();
|
let portable_types: PortableRegistry = registry.into();
|
||||||
|
|
||||||
let type_gen = TypeGenerator::new(
|
let type_gen = TypeGenerator::new(
|
||||||
@@ -832,7 +832,7 @@ fn modules() {
|
|||||||
quote! {
|
quote! {
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::root;
|
use super::root;
|
||||||
pub mod modules {
|
pub mod m {
|
||||||
use super::root;
|
use super::root;
|
||||||
pub mod a {
|
pub mod a {
|
||||||
use super::root;
|
use super::root;
|
||||||
@@ -842,7 +842,7 @@ fn modules() {
|
|||||||
|
|
||||||
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
||||||
pub struct Bar {
|
pub struct Bar {
|
||||||
pub a: root::subxt_codegen::types::tests::modules::a::Foo,
|
pub a: root::subxt_codegen::types::tests::m::a::Foo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -855,7 +855,7 @@ fn modules() {
|
|||||||
|
|
||||||
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
#[derive(::subxt::codec::Encode, ::subxt::codec::Decode)]
|
||||||
pub struct Foo {
|
pub struct Foo {
|
||||||
pub a: root::subxt_codegen::types::tests::modules::a::b::Bar,
|
pub a: root::subxt_codegen::types::tests::m::a::b::Bar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -157,7 +157,14 @@ impl<T: Config> Client<T> {
|
|||||||
&self.metadata
|
&self.metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the system properties
|
/// Returns the properties defined in the chain spec as a JSON object.
|
||||||
|
///
|
||||||
|
/// # Note
|
||||||
|
///
|
||||||
|
/// Many chains use this to define common properties such as `token_decimals` and `token_symbol`
|
||||||
|
/// required for UIs, but this is merely a convention. It is up to the library user to
|
||||||
|
/// deserialize the JSON into the appropriate type or otherwise extract the properties defined
|
||||||
|
/// in the target chain's spec.
|
||||||
pub fn properties(&self) -> &SystemProperties {
|
pub fn properties(&self) -> &SystemProperties {
|
||||||
&self.properties
|
&self.properties
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,6 +143,11 @@ pub struct PalletMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PalletMetadata {
|
impl PalletMetadata {
|
||||||
|
/// Get the name of the pallet.
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
/// Encode a call based on this pallet metadata.
|
/// Encode a call based on this pallet metadata.
|
||||||
pub fn encode_call<C>(&self, call: &C) -> Result<Encoded, MetadataError>
|
pub fn encode_call<C>(&self, call: &C) -> Result<Encoded, MetadataError>
|
||||||
where
|
where
|
||||||
|
|||||||
+2
-11
@@ -141,17 +141,8 @@ impl From<u32> for BlockNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// System properties for a Substrate-based runtime
|
/// Arbitrary properties defined in the chain spec as a JSON object.
|
||||||
#[derive(serde::Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
pub type SystemProperties = serde_json::Map<String, serde_json::Value>;
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct SystemProperties {
|
|
||||||
/// The address format
|
|
||||||
pub ss58_format: u8,
|
|
||||||
/// The number of digits after the decimal point in the native token
|
|
||||||
pub token_decimals: u8,
|
|
||||||
/// The symbol of the native token
|
|
||||||
pub token_symbol: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Possible transaction status events.
|
/// Possible transaction status events.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -15,34 +15,12 @@
|
|||||||
// along with subxt. If not, see <http://www.gnu.org/licenses/>.
|
// along with subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::test_context;
|
use crate::test_context;
|
||||||
use std::time::{
|
|
||||||
SystemTime,
|
|
||||||
UNIX_EPOCH,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn storage_get_current_timestamp() {
|
async fn storage_get_current_timestamp() {
|
||||||
let sys_timestamp = SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_millis() as u64;
|
|
||||||
let cxt = test_context().await;
|
let cxt = test_context().await;
|
||||||
|
|
||||||
// wait until blocks are produced to get the timestamp
|
let timestamp = cxt.api.storage().timestamp().now(None).await;
|
||||||
let mut sub = cxt.client().rpc().subscribe_blocks().await.unwrap();
|
|
||||||
let block_hash = loop {
|
|
||||||
if let Ok(Some(block)) = sub.next().await {
|
|
||||||
break block.hash()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let timestamp = cxt
|
assert!(timestamp.is_ok())
|
||||||
.api
|
|
||||||
.storage()
|
|
||||||
.timestamp()
|
|
||||||
.now(Some(block_hash))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(timestamp > sys_timestamp)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user