Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion subxt/src/config/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

//! Substrate specific configuration

use super::{Config, DefaultExtrinsicParamsBuilder, DefaultTransactionExtensions, Hasher, Header};
use super::{
Config, DefaultExtrinsicParamsBuilder, DefaultTransactionExtensions, HashFor, Hasher, Header,
};
use crate::config::Hash;
use crate::metadata::{ArcMetadata, Metadata};
use crate::utils::RangeMap;
Expand Down Expand Up @@ -102,6 +104,7 @@ impl SubstrateConfigBuilder {
legacy_types: self.legacy_types,
spec_and_transaction_version_for_block_number: self
.spec_and_transaction_version_for_block_number,
genesis_hash: self.genesis_hash,
metadata_for_spec_version: self.metadata_for_spec_version,
}),
}
Expand Down Expand Up @@ -132,6 +135,7 @@ pub struct SubstrateConfig {
struct SubstrateConfigInner {
legacy_types: Option<ChainTypeRegistry>,
spec_and_transaction_version_for_block_number: RangeMap<u64, (u32, u32)>,
genesis_hash: Option<H256>,
metadata_for_spec_version: RwLock<HashMap<u32, ArcMetadata>>,
}

Expand Down Expand Up @@ -191,6 +195,10 @@ impl Config for SubstrateConfig {
.cloned()
}

fn genesis_hash(&self) -> Option<HashFor<Self>> {
self.inner.genesis_hash
}

fn set_metadata_for_spec_version(&self, spec_version: u32, metadata: ArcMetadata) {
self.inner
.metadata_for_spec_version
Expand Down Expand Up @@ -558,4 +566,20 @@ mod test {
serde_json::from_str(numeric_block_number_json).expect("valid block header");
assert_eq!(header.number(), 4);
}

#[test]
fn builder_propagates_genesis_hash() {
let hash = H256::from([42u8; 32]);
let config = SubstrateConfig::builder().set_genesis_hash(hash).build();
assert_eq!(
<SubstrateConfig as Config>::genesis_hash(&config),
Some(hash)
);
}

#[test]
fn builder_without_genesis_hash_returns_none() {
let config = SubstrateConfig::builder().build();
assert_eq!(<SubstrateConfig as Config>::genesis_hash(&config), None);
}
}
Loading