referrerpolicy=no-referrer-when-downgrade

bp_header_chain/
storage_keys.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Bridges Common is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Storage keys of bridge GRANDPA pallet.
18
19/// Name of the `IsHalted` storage value.
20pub const PALLET_OPERATING_MODE_VALUE_NAME: &str = "PalletOperatingMode";
21/// Name of the `BestFinalized` storage value.
22pub const BEST_FINALIZED_VALUE_NAME: &str = "BestFinalized";
23/// Name of the `CurrentAuthoritySet` storage value.
24pub const CURRENT_AUTHORITY_SET_VALUE_NAME: &str = "CurrentAuthoritySet";
25
26use sp_core::storage::StorageKey;
27
28/// Storage key of the `PalletOperatingMode` variable in the runtime storage.
29pub fn pallet_operating_mode_key(pallet_prefix: &str) -> StorageKey {
30	StorageKey(
31		bp_runtime::storage_value_final_key(
32			pallet_prefix.as_bytes(),
33			PALLET_OPERATING_MODE_VALUE_NAME.as_bytes(),
34		)
35		.to_vec(),
36	)
37}
38
39/// Storage key of the `CurrentAuthoritySet` variable in the runtime storage.
40pub fn current_authority_set_key(pallet_prefix: &str) -> StorageKey {
41	StorageKey(
42		bp_runtime::storage_value_final_key(
43			pallet_prefix.as_bytes(),
44			CURRENT_AUTHORITY_SET_VALUE_NAME.as_bytes(),
45		)
46		.to_vec(),
47	)
48}
49
50/// Storage key of the best finalized header number and hash value in the runtime storage.
51pub fn best_finalized_key(pallet_prefix: &str) -> StorageKey {
52	StorageKey(
53		bp_runtime::storage_value_final_key(
54			pallet_prefix.as_bytes(),
55			BEST_FINALIZED_VALUE_NAME.as_bytes(),
56		)
57		.to_vec(),
58	)
59}
60
61#[cfg(test)]
62mod tests {
63	use super::*;
64	use hex_literal::hex;
65
66	#[test]
67	fn pallet_operating_mode_key_computed_properly() {
68		// If this test fails, then something has been changed in module storage that is breaking
69		// compatibility with previous pallet.
70		let storage_key = pallet_operating_mode_key("BridgeGrandpa").0;
71		assert_eq!(
72			storage_key,
73			hex!("0b06f475eddb98cf933a12262e0388de0f4cf0917788d791142ff6c1f216e7b3").to_vec(),
74			"Unexpected storage key: {}",
75			hex::encode(&storage_key),
76		);
77	}
78
79	#[test]
80	fn current_authority_set_key_computed_properly() {
81		// If this test fails, then something has been changed in module storage that is breaking
82		// compatibility with previous pallet.
83		let storage_key = current_authority_set_key("BridgeGrandpa").0;
84		assert_eq!(
85			storage_key,
86			hex!("0b06f475eddb98cf933a12262e0388de24a7b8b5717ea33346fa595a66ccbcb0").to_vec(),
87			"Unexpected storage key: {}",
88			hex::encode(&storage_key),
89		);
90	}
91
92	#[test]
93	fn best_finalized_key_computed_properly() {
94		// If this test fails, then something has been changed in module storage that is breaking
95		// compatibility with previous pallet.
96		let storage_key = best_finalized_key("BridgeGrandpa").0;
97		assert_eq!(
98			storage_key,
99			hex!("0b06f475eddb98cf933a12262e0388dea4ebafdd473c549fdb24c5c991c5591c").to_vec(),
100			"Unexpected storage key: {}",
101			hex::encode(&storage_key),
102		);
103	}
104}