-
Notifications
You must be signed in to change notification settings - Fork 12
Copy v13 metadata from substrate, move new scale-info version to v14 #12
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3f18a83
Copy v13 metadata from substrate, move new scale-info version to v14
ascjones 2d3c2ee
Fmt
ascjones 4a9fcdd
Remove common lib types
ascjones 3b08f72
Extract decode different types
ascjones 7085a86
Update CI to check v14
ascjones f5c1bcf
Add Storage NMap to v14
ascjones 88c398d
Bump version
ascjones f75ac0e
NMap keys is a Type
ascjones fe50b8a
Fix NMap IntoPortable
ascjones 9a25054
Update frame-metadata/src/v13.rs
ascjones 3896be7
Remove All the metadata comments
ascjones 00450bc
More clean up of v12 and v13
ascjones 44d7a37
review: fix comment
ascjones 268bfc7
Fix v13 Debug derives
ascjones File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,164 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2018-2020 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use codec::{Encode, Output}; | ||
|
|
||
| cfg_if::cfg_if! { | ||
| if #[cfg(feature = "std")] { | ||
| use codec::{Decode, Error, Input}; | ||
| pub type StringBuf = String; | ||
| } else { | ||
| extern crate alloc; | ||
| use alloc::vec::Vec; | ||
|
|
||
| /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. | ||
| /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. | ||
| pub type StringBuf = &'static str; | ||
| } | ||
| } | ||
|
|
||
| /// A type that decodes to a different type than it encodes. | ||
| /// The user needs to make sure that both types use the same encoding. | ||
| /// | ||
| /// For example a `&'static [ &'static str ]` can be decoded to a `Vec<String>`. | ||
| #[derive(Clone)] | ||
| pub enum DecodeDifferent<B, O> | ||
| where | ||
| B: 'static, | ||
| O: 'static, | ||
| { | ||
| Encode(B), | ||
| Decoded(O), | ||
| } | ||
|
|
||
| impl<B, O> Encode for DecodeDifferent<B, O> | ||
| where | ||
| B: Encode + 'static, | ||
| O: Encode + 'static, | ||
| { | ||
| fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) { | ||
| match self { | ||
| DecodeDifferent::Encode(b) => b.encode_to(dest), | ||
| DecodeDifferent::Decoded(o) => o.encode_to(dest), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<B, O> codec::EncodeLike for DecodeDifferent<B, O> | ||
| where | ||
| B: Encode + 'static, | ||
| O: Encode + 'static, | ||
| { | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl<B, O> Decode for DecodeDifferent<B, O> | ||
| where | ||
| B: 'static, | ||
| O: Decode + 'static, | ||
| { | ||
| fn decode<I: Input>(input: &mut I) -> Result<Self, Error> { | ||
| <O>::decode(input).map(|val| DecodeDifferent::Decoded(val)) | ||
| } | ||
| } | ||
|
|
||
| impl<B, O> PartialEq for DecodeDifferent<B, O> | ||
| where | ||
| B: Encode + Eq + PartialEq + 'static, | ||
| O: Encode + Eq + PartialEq + 'static, | ||
| { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| self.encode() == other.encode() | ||
| } | ||
| } | ||
|
|
||
| impl<B, O> Eq for DecodeDifferent<B, O> | ||
| where | ||
| B: Encode + Eq + PartialEq + 'static, | ||
| O: Encode + Eq + PartialEq + 'static, | ||
| { | ||
| } | ||
|
|
||
| impl<B, O> core::fmt::Debug for DecodeDifferent<B, O> | ||
| where | ||
| B: core::fmt::Debug + Eq + 'static, | ||
| O: core::fmt::Debug + Eq + 'static, | ||
| { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { | ||
| match self { | ||
| DecodeDifferent::Encode(b) => b.fmt(f), | ||
| DecodeDifferent::Decoded(o) => o.fmt(f), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl<B, O> serde::Serialize for DecodeDifferent<B, O> | ||
| where | ||
| B: serde::Serialize + 'static, | ||
| O: serde::Serialize + 'static, | ||
| { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| { | ||
| match self { | ||
| DecodeDifferent::Encode(b) => b.serialize(serializer), | ||
| DecodeDifferent::Decoded(o) => o.serialize(serializer), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub type DecodeDifferentArray<B, O = B> = DecodeDifferent<&'static [B], Vec<O>>; | ||
|
|
||
| pub type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>; | ||
|
|
||
| /// Newtype wrapper for support encoding functions (actual the result of the function). | ||
| #[derive(Clone, Eq)] | ||
| pub struct FnEncode<E>(pub fn() -> E) | ||
| where | ||
| E: Encode + 'static; | ||
|
|
||
| impl<E: Encode> Encode for FnEncode<E> { | ||
| fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) { | ||
| self.0().encode_to(dest); | ||
| } | ||
| } | ||
|
|
||
| impl<E: Encode> codec::EncodeLike for FnEncode<E> {} | ||
|
|
||
| impl<E: Encode + PartialEq> PartialEq for FnEncode<E> { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| self.0().eq(&other.0()) | ||
| } | ||
| } | ||
|
|
||
| impl<E: Encode + core::fmt::Debug> core::fmt::Debug for FnEncode<E> { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { | ||
| self.0().fmt(f) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl<E: Encode + serde::Serialize> serde::Serialize for FnEncode<E> { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| { | ||
| self.0().serialize(serializer) | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.