From f64d78584e6592bf7e9463ee81b909670354a993 Mon Sep 17 00:00:00 2001 From: GabrielMartinezRodriguez Date: Tue, 23 Jan 2024 12:58:44 +0100 Subject: [PATCH] chore: getHashOfCurrentCode --- precompiles/upgrade-runtime-controller/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/precompiles/upgrade-runtime-controller/src/lib.rs b/precompiles/upgrade-runtime-controller/src/lib.rs index 78f1f264..d55bb681 100644 --- a/precompiles/upgrade-runtime-controller/src/lib.rs +++ b/precompiles/upgrade-runtime-controller/src/lib.rs @@ -329,4 +329,17 @@ where None => Ok(H256::default()), } } + + #[precompile::public("getHashOfCurrentCode()")] + #[precompile::view] + fn get_hash_of_current_code(handle: &mut impl PrecompileHandle) -> EvmResult { + handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; + + let hash = pallet_upgrade_runtime_proposal::Pallet::::get_current_code_hash(); + + match hash { + Some(hash) => Ok(hash.into()), + None => Ok(H256::default()), + } + } }