diff --git a/src/client.rs b/src/client.rs index 0ae001cf18..8807588277 100644 --- a/src/client.rs +++ b/src/client.rs @@ -17,7 +17,6 @@ use futures::future; use sp_runtime::traits::Hash; pub use sp_runtime::traits::SignedExtension; -pub use sp_version::RuntimeVersion; use crate::{ error::Error, @@ -31,6 +30,7 @@ use crate::{ rpc::{ Rpc, RpcClient, + RuntimeVersion, SystemProperties, }, storage::StorageClient, @@ -132,7 +132,7 @@ impl std::fmt::Debug for Client { .field("metadata", &"") .field("events_decoder", &"") .field("properties", &self.properties) - .field("runtime_version", &self.runtime_version.to_string()) + .field("runtime_version", &self.runtime_version) .field("iter_page_size", &self.iter_page_size) .finish() } diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index 77e6853f78..d061e76421 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -39,9 +39,9 @@ pub use self::{ }; use sp_runtime::traits::SignedExtension; -use sp_version::RuntimeVersion; use crate::{ + rpc::RuntimeVersion, Config, Encoded, Error, diff --git a/src/rpc.rs b/src/rpc.rs index 470a4166c0..aad71203d9 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -21,7 +21,10 @@ // Related: https://github.com/paritytech/subxt/issues/66 #![allow(irrefutable_let_patterns)] -use std::sync::Arc; +use std::{ + collections::HashMap, + sync::Arc, +}; use codec::{ Decode, @@ -68,7 +71,6 @@ use sp_runtime::generic::{ Block, SignedBlock, }; -use sp_version::RuntimeVersion; use crate::{ error::Error, @@ -165,6 +167,33 @@ pub enum SubstrateTransactionStatus { Invalid, } +/// This contains the runtime version information necessary to make transactions, as obtained from +/// the RPC call `state_getRuntimeVersion`, +#[derive(Debug, Clone, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RuntimeVersion { + /// Version of the runtime specification. A full-node will not attempt to use its native + /// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, + /// `spec_version` and `authoring_version` are the same between Wasm and native. + pub spec_version: u32, + + /// All existing dispatches are fully compatible when this number doesn't change. If this + /// number changes, then `spec_version` must change, also. + /// + /// This number must change when an existing dispatchable (module ID, dispatch ID) is changed, + /// either through an alteration in its user-level semantics, a parameter + /// added/removed/changed, a dispatchable being removed, a module being removed, or a + /// dispatchable/module changing its index. + /// + /// It need *not* change when a new module is added or when a dispatchable is added. + pub transaction_version: u32, + + /// The other fields present may vary and aren't necessary for `subxt`; they are preserved in + /// this map. + #[serde(flatten)] + pub other: HashMap, +} + /// Rpc client wrapper. /// This is workaround because adding generic types causes the macros to fail. #[derive(Clone)] @@ -597,3 +626,34 @@ impl Rpc { Ok(self.client.request("author_hasKey", params).await?) } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_deser_runtime_version() { + let val: RuntimeVersion = serde_json::from_str( + r#"{ + "specVersion": 123, + "transactionVersion": 456, + "foo": true, + "wibble": [1,2,3] + }"#, + ) + .expect("deserializing failed"); + + let mut m = std::collections::HashMap::new(); + m.insert("foo".to_owned(), serde_json::json!(true)); + m.insert("wibble".to_owned(), serde_json::json!([1, 2, 3])); + + assert_eq!( + val, + RuntimeVersion { + spec_version: 123, + transaction_version: 456, + other: m + } + ); + } +}