-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type info to oracle data #1184
base: master
Are you sure you want to change the base?
Changes from all commits
ddf7184
349db12
7d6edc7
54b3da6
c2420e5
fef7477
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
|
||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
use sp_std::vec::Vec; | ||
|
||
#[cfg(test)] | ||
mod mock; | ||
|
@@ -55,13 +56,22 @@ pub mod module { | |
type WeightInfo: WeightInfo; | ||
} | ||
|
||
/// Oracle Info for oracle data | ||
#[derive(Clone, Encode, Decode, Eq, PartialEqNoBound, RuntimeDebug, TypeInfo)] | ||
#[scale_info(skip_type_params(T))] | ||
pub struct OracleInfo<T: Config> { | ||
pub oracle_data: BoundedVec<u8, T::MaxOracleValueLength>, | ||
pub oracle_type: Vec<u8>, | ||
} | ||
|
||
/// Storage for oracle info to be passed to programs. | ||
#[pallet::storage] | ||
#[pallet::getter(fn oracle_data)] | ||
pub type OracleData<T: Config> = StorageMap< | ||
_, | ||
Blake2_128Concat, | ||
BoundedVec<u8, T::MaxOracleKeyLength>, | ||
BoundedVec<u8, T::MaxOracleValueLength>, | ||
OracleInfo<T>, | ||
OptionQuery, | ||
>; | ||
|
||
|
@@ -92,8 +102,11 @@ pub mod module { | |
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"), | ||
OracleInfo { | ||
oracle_data: BoundedVec::try_from(block_number.encode()) | ||
.expect("Block number fits in bounded vec; qed"), | ||
oracle_type: "u32".as_bytes().to_vec(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not need to say something like It seems strange that elsewhere we use JSON for program aux data / config, but use scale here. Using both would mean programs need to have dependencies for both json and scale. If i just read There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ye, I chose scale because it plays really nicely with substrate, I mean Im open for other optinons here, but pretty much we should force all oracle info data types to be the same type either scale or json (im still in favour of scale in substrate) |
||
}, | ||
); | ||
T::WeightInfo::on_initialize() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-code blocks there should only be a single tick used.