-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integrate oracle pallet * integrate oracle data to core * test oracle data fetch * parameterized bounded vecs * fmt * clean * remove unwrap * add build checks * add changelog * merge * clean * add benchmarks * fix
- Loading branch information
1 parent
aa4c3d9
commit 5d64794
Showing
19 changed files
with
545 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[package] | ||
name ="pallet-oracle" | ||
version ='0.2.0-rc.1' | ||
authors =['Entropy Cryptography <engineering@entropy.xyz>'] | ||
homepage ='https://entropy.xyz/' | ||
license ='AGPL-3.0-or-later' | ||
repository='https://github.com/entropyxyz/entropy-core' | ||
edition ='2021' | ||
publish =false | ||
|
||
[dependencies] | ||
codec ={ package="parity-scale-codec", version="3.6.3", default-features=false, features=["derive"] } | ||
scale-info={ version="2.11", default-features=false, features=["derive"] } | ||
|
||
frame-benchmarking={ version="29.0.0", default-features=false, optional=true } | ||
frame-support ={ version="29.0.0", default-features=false } | ||
frame-system ={ version="29.0.0", default-features=false } | ||
sp-runtime ={ version="32.0.0", default-features=false } | ||
sp-std ={ version="14.0.0", default-features=false } | ||
|
||
[dev-dependencies] | ||
sp-core={ version="29.0.0" } | ||
sp-io ={ version="31.0.0" } | ||
|
||
[features] | ||
default=["std"] | ||
runtime-benchmarks=[ | ||
'frame-benchmarking', | ||
'frame-support/runtime-benchmarks', | ||
'frame-system/runtime-benchmarks', | ||
] | ||
std=[ | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
'frame-benchmarking/std', | ||
] | ||
try-runtime=["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2023 Entropy Cryptography Inc. | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// //! Benchmarking setup for pallet-oracle | ||
|
||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as Oracle; | ||
use frame_benchmarking::benchmarks; | ||
|
||
benchmarks! { | ||
on_initialize { | ||
}: { | ||
Oracle::<T>::on_initialize(50u32.into()); | ||
} verify { | ||
assert_eq!(OracleData::<T>::get(BoundedVec::try_from("block_number_entropy".encode()).unwrap()).unwrap()[0], 50); | ||
} | ||
|
||
impl_benchmark_test_suite!(Oracle, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (C) 2023 Entropy Cryptography Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! # Programs Oracle | ||
//! | ||
//! ## Overview | ||
//! | ||
//! A pallet to manage oracle data for programs. | ||
//! | ||
//! Oracle data is stored in OracleData storage and can be pointed to and pulled in for programs | ||
//! | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
#![allow(clippy::unused_unit)] | ||
|
||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[cfg(test)] | ||
mod mock; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
pub mod weights; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
mod benchmarking; | ||
|
||
pub use module::*; | ||
|
||
#[frame_support::pallet] | ||
pub mod module { | ||
use super::*; | ||
pub use crate::weights::WeightInfo; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
/// The maximum amount of owned programs. | ||
type MaxOracleKeyLength: Get<u32>; | ||
/// The maximum amount of owned programs. | ||
type MaxOracleValueLength: Get<u32>; | ||
/// Weight information for the extrinsics in this module. | ||
type WeightInfo: WeightInfo; | ||
} | ||
|
||
#[pallet::storage] | ||
#[pallet::getter(fn oracle_data)] | ||
pub type OracleData<T: Config> = StorageMap< | ||
_, | ||
Blake2_128Concat, | ||
BoundedVec<u8, T::MaxOracleKeyLength>, | ||
BoundedVec<u8, T::MaxOracleValueLength>, | ||
OptionQuery, | ||
>; | ||
|
||
#[pallet::pallet] | ||
#[pallet::without_storage_info] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::genesis_config] | ||
#[derive(frame_support::DefaultNoBound)] | ||
pub struct GenesisConfig<T: Config> { | ||
#[serde(skip)] | ||
_config: sp_std::marker::PhantomData<T>, | ||
} | ||
|
||
#[pallet::genesis_build] | ||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> { | ||
fn build(&self) { | ||
// Makes sure key chosen can fit in bounded vec | ||
assert!("block_number_entropy".encode().len() as u32 <= T::MaxOracleKeyLength::get()); | ||
// Makes sure block number can fit in bounded vec | ||
assert!(u64::MAX.encode().len() as u32 <= T::MaxOracleKeyLength::get()); | ||
} | ||
} | ||
|
||
#[pallet::hooks] | ||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { | ||
fn on_initialize(block_number: BlockNumberFor<T>) -> Weight { | ||
OracleData::<T>::insert( | ||
BoundedVec::try_from("block_number_entropy".encode()) | ||
.expect("Key fits in bounded vec; qed"), | ||
BoundedVec::try_from(block_number.encode()) | ||
.expect("Block number fits in bounded vec; qed"), | ||
); | ||
T::WeightInfo::on_initialize() | ||
} | ||
} | ||
|
||
#[pallet::error] | ||
pub enum Error<T> {} | ||
|
||
#[pallet::event] | ||
pub enum Event<T: Config> {} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> {} | ||
} |
Oops, something went wrong.