Skip to content

Commit

Permalink
clean keys
Browse files Browse the repository at this point in the history
  • Loading branch information
al3mart committed Mar 2, 2024
1 parent aad8add commit 67e11f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions runtime/src/extensions/ext_impl/read_state.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use cumulus_pallet_parachain_system::LastRelayChainBlockNumber;
use cumulus_primitives_core::relay_chain::BlockNumber;
use frame_support::pallet_prelude::*;
use pallet_contracts::chain_extension::{
Environment, Ext, InitState
};
use pop_api_primitives::storage_keys::RuntimeStateKeys;
use pop_api_primitives::storage_keys::ParachainSystemKeys;
use log;
use codec::Decode;

Expand All @@ -16,18 +15,19 @@ where
E: Ext<T = T>,
{
let mut env = env.buf_in_buf_out();
// TODO: Substitue len u32 with pop-api::src::impls::pop_network::StringLimit.
// TODO: Substitue len u32 with pop_api::src::impls::pop_network::StringLimit.
// Move StringLimit to pop_api_primitives first.
let len = env.in_len();
let key: RuntimeStateKeys::ParachainSystemKeys = env.read_as_unbounded(len)?;
let len: u32 = env.in_len();
let key: ParachainSystemKeys = env.read_as_unbounded(len)?;

match key {
LastRelayChainBlockNumber => {
let relay_block_num: BlockNumber = last_relay_block_number();
let relay_block_num: BlockNumber = cumulus_pallet_parachain_system::LastRelayChainBlockNumber::get();
log::debug!(
target:LOG_TARGET,
"Last Relay Chain Block Number is: {:?}.", relay_block_num
);
//Ok(relay_block_num)
Ok(())
},
_ => Err(DispatchError::Other("Unable to read provided key.")),
Expand Down
9 changes: 4 additions & 5 deletions runtime/src/extensions/pop_api_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use pallet_contracts::chain_extension::{
};
use sp_core::crypto::UncheckedFrom;
use sp_runtime::{traits::Dispatchable, DispatchError};
use pop_api_primitives::storage_keys::RuntimeStateKeys::ParachainSystemKeys;

use crate::extensions::ext_impl::{dispatch::dispatch, read_state::read_state};

Expand All @@ -31,7 +30,7 @@ fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchE
#[derive(Debug)]
enum FuncId {
CallRuntime,
QueryState(RuntimeStateKeys),
QueryState,
}

impl TryFrom<u16> for FuncId {
Expand All @@ -40,7 +39,7 @@ impl TryFrom<u16> for FuncId {
fn try_from(func_id: u16) -> Result<Self, Self::Error> {
let id = match func_id {
0xfecb => Self::CallRuntime,
0xfeca => Self::QueryState(ParachainSystemKeys(LastRelayChainBlockNumber)),
0xfeca => Self::QueryState,
_ => {
log::error!("Called an unregistered `func_id`: {:}", func_id);
return Err(DispatchError::Other("Unimplemented func_id"));
Expand All @@ -53,7 +52,7 @@ impl TryFrom<u16> for FuncId {

impl<T> ChainExtension<T> for PopApiExtension
where
T: pallet_contracts::Config,
T: pallet_contracts::Config + cumulus_pallet_parachain_system::Config,
<T as SysConfig>::AccountId: UncheckedFrom<<T as SysConfig>::Hash> + AsRef<[u8]>,
<T as SysConfig>::RuntimeCall: Parameter
+ Dispatchable<RuntimeOrigin = <T as SysConfig>::RuntimeOrigin, PostInfo = PostDispatchInfo>
Expand All @@ -69,7 +68,7 @@ where
let func_id = FuncId::try_from(env.func_id())?;
match func_id {
FuncId::CallRuntime => dispatch::<T, E>(env)?,
FuncId::QueryState(RuntimeStateKeys) => read_state::<T, E>(env)?,
FuncId::QueryState => read_state::<T, E>(env)?,
}

Ok(RetVal::Converging(0))
Expand Down

0 comments on commit 67e11f0

Please sign in to comment.