├── .github ├── dependabot.yml └── workflows │ ├── deny.yml │ ├── lint.yml │ └── rust.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE2 ├── LICENSE-GPL3 ├── README.md ├── RELEASING.md ├── deny.toml ├── frame-metadata ├── Cargo.toml ├── README.md ├── src │ ├── decode_different.rs │ ├── lib.rs │ ├── v10.rs │ ├── v11.rs │ ├── v12.rs │ ├── v13.rs │ ├── v14.rs │ ├── v15.rs │ ├── v16.rs │ ├── v8.rs │ └── v9.rs └── test_data │ ├── ksm_metadata_v10.bin │ ├── ksm_metadata_v11.bin │ ├── ksm_metadata_v12.bin │ ├── ksm_metadata_v13.bin │ ├── ksm_metadata_v14.bin │ └── ksm_metadata_v9.bin └── rustfmt.toml /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: '/' 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /.github/workflows/deny.yml: -------------------------------------------------------------------------------- 1 | name: Cargo deny 2 | 3 | on: 4 | pull_request: 5 | schedule: 6 | - cron: '0 0 * * *' 7 | push: 8 | branches: 9 | - master 10 | tags: 11 | - v* 12 | paths-ignore: 13 | - 'README.md' 14 | jobs: 15 | cargo-deny: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Cancel Previous Runs 19 | uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 20 | with: 21 | access_token: ${{ github.token }} 22 | - name: Checkout sources & submodules 23 | uses: actions/checkout@v4 24 | with: 25 | fetch-depth: 5 26 | submodules: recursive 27 | - name: Cargo deny 28 | uses: EmbarkStudios/cargo-deny-action@v2 29 | with: 30 | command: "check --hide-inclusion-graph" 31 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Check style 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | tags: 9 | - v* 10 | paths-ignore: 11 | - 'README.md' 12 | jobs: 13 | ## Check stage 14 | check-fmt: 15 | name: Check RustFmt 16 | runs-on: ubuntu-latest 17 | env: 18 | RUST_BACKTRACE: full 19 | steps: 20 | - name: Cancel Previous Runs 21 | uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 22 | with: 23 | access_token: ${{ github.token }} 24 | - name: Checkout sources & submodules 25 | uses: actions/checkout@v4 26 | with: 27 | fetch-depth: 5 28 | submodules: recursive 29 | - name: Add rustfmt 30 | run: rustup component add rustfmt 31 | - name: rust-fmt check 32 | uses: actions-rs/cargo@v1 33 | with: 34 | command: fmt 35 | args: --all -- --check 36 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Compilation and Testing Suite 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | tags: 9 | - v* 10 | paths-ignore: 11 | - 'README.md' 12 | 13 | env: 14 | CARGO_TERM_COLOR: always 15 | 16 | jobs: 17 | fmt: 18 | name: Cargo fmt 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Checkout sources 22 | uses: actions/checkout@v4 23 | 24 | - name: Install Rust nightly toolchain 25 | uses: actions-rs/toolchain@v1 26 | with: 27 | profile: minimal 28 | toolchain: nightly 29 | override: true 30 | components: rustfmt 31 | 32 | - name: Rust Cache 33 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 34 | 35 | - name: Cargo fmt 36 | uses: actions-rs/cargo@v1.0.3 37 | with: 38 | command: fmt 39 | args: --all -- --check 40 | 41 | docs: 42 | name: Check documentation 43 | runs-on: ubuntu-latest 44 | steps: 45 | - name: Checkout sources 46 | uses: actions/checkout@v4 47 | 48 | - name: Install Rust stable toolchain 49 | uses: actions-rs/toolchain@v1 50 | with: 51 | profile: minimal 52 | toolchain: stable 53 | override: true 54 | 55 | - name: Rust Cache 56 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 57 | 58 | - name: Check internal documentation links 59 | run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items 60 | 61 | - name: Run cargo test on documentation 62 | uses: actions-rs/cargo@v1.0.3 63 | with: 64 | command: test 65 | args: --doc 66 | 67 | tests: 68 | name: Cargo test 69 | runs-on: ubuntu-latest 70 | steps: 71 | - name: Checkout sources 72 | uses: actions/checkout@v4 73 | 74 | - name: Install Rust stable toolchain 75 | uses: actions-rs/toolchain@v1 76 | with: 77 | profile: minimal 78 | toolchain: stable 79 | override: true 80 | 81 | - name: Rust Cache 82 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 83 | 84 | - name: Cargo test 85 | uses: actions-rs/cargo@v1.0.3 86 | with: 87 | command: test 88 | args: --all-targets --workspace 89 | 90 | clippy: 91 | name: Cargo clippy 92 | runs-on: ubuntu-latest 93 | steps: 94 | - name: Checkout sources 95 | uses: actions/checkout@v4 96 | 97 | - name: Install Rust stable toolchain 98 | uses: actions-rs/toolchain@v1 99 | with: 100 | profile: minimal 101 | toolchain: stable 102 | components: clippy 103 | override: true 104 | 105 | - name: Rust Cache 106 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 107 | 108 | - name: Run clippy 109 | uses: actions-rs/cargo@v1 110 | with: 111 | command: clippy 112 | args: --all-targets -- -D warnings 113 | 114 | check-wasm: 115 | name: Check WASM 116 | runs-on: ubuntu-latest 117 | steps: 118 | - name: Checkout sources 119 | uses: actions/checkout@v4 120 | 121 | - name: Install Rust stable toolchain 122 | uses: actions-rs/toolchain@v1 123 | with: 124 | profile: minimal 125 | toolchain: stable 126 | components: clippy 127 | target: wasm32-unknown-unknown 128 | override: true 129 | 130 | - name: Rust Cache 131 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 132 | 133 | - name: Install cargo-hack 134 | uses: baptiste0928/cargo-install@v3 135 | with: 136 | crate: cargo-hack 137 | version: 0.5 138 | 139 | - name: Checking wasm32 (v14) 140 | run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features current --skip legacy --depth 4 --target wasm32-unknown-unknown 141 | 142 | - name: Checking wasm32 (all features) 143 | run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --skip decode,serde_full --depth 4 --target wasm32-unknown-unknown 144 | 145 | check-features: 146 | name: Check Features 147 | runs-on: ubuntu-latest 148 | steps: 149 | - name: Checkout sources 150 | uses: actions/checkout@v4 151 | 152 | - name: Install Rust stable toolchain 153 | uses: actions-rs/toolchain@v1 154 | with: 155 | profile: minimal 156 | toolchain: stable 157 | components: clippy 158 | override: true 159 | 160 | - name: Rust Cache 161 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 162 | 163 | - name: Install cargo-hack 164 | uses: baptiste0928/cargo-install@v3 165 | with: 166 | crate: cargo-hack 167 | version: 0.5 168 | 169 | - name: Checking v14 feature combinations (native) 170 | run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features current --skip legacy --depth 4 171 | 172 | - name: Checking feature combinations excluding decode/serde_full (native) 173 | run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --skip decode,serde_full --depth 4 174 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Changelog 3 | 4 | All notable changes to this project will be documented in this file. 5 | 6 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 7 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 8 | 9 | ## [Unreleased] 10 | 11 | ## [23.0.0] - 2025-05-06 12 | 13 | This version stabilizes metadata V16, moving it from being marked as "unstable" and hidden behind that feature flag, to being "current" and having version 16 rather than `u32::MAX`. 14 | 15 | ## [22.0.0] - 2025-04-24 16 | 17 | ### Changed 18 | 19 | - Alter the deprecation information metadata to remove duplicate/confusing states [#101](https://github.com/paritytech/frame-metadata/pull/101) 20 | 21 | ## [21.0.0] - 2025-04-01 22 | 23 | ### Changed 24 | 25 | - Address some small niggles in the unstable V16 metadata [#98](https://github.com/paritytech/frame-metadata/pull/98) 26 | 27 | ## [20.0.0] - 2025-02-20 28 | 29 | Metadata version 16 is currently unstable and can be enabled using the unstable feature flag. 30 | 31 | ### Added 32 | 33 | - Add Runtime Api version to v16 [#92](https://github.com/paritytech/frame-metadata/pull/92) 34 | 35 | ## [19.0.0] - 2025-02-11 36 | 37 | Metadata version 16 is currently unstable and can be enabled using the unstable feature flag. 38 | 39 | ### Added 40 | 41 | - v16: Add view functions to the pallets metadata [#89](https://github.com/paritytech/frame-metadata/pull/89) 42 | 43 | ## [18.0.0] - 2024-11-13 44 | 45 | ### Changed 46 | 47 | - v16: ExtrinsicMetadata extensions [#86](https://github.com/paritytech/frame-metadata/pull/86) 48 | 49 | ## [17.0.0] - 2024-10-16 50 | 51 | ### Added 52 | 53 | - v16: Add unstable metadata v16 [#82](https://github.com/paritytech/frame-metadata/pull/82) 54 | 55 | ## [16.0.0] - 2023-06-29 56 | 57 | ### Changed 58 | 59 | - Stabilize V15 metadata [#66](https://github.com/paritytech/frame-metadata/pull/66) 60 | 61 | ## [15.2.0] - 2023-06-27 62 | 63 | ### Added 64 | 65 | - V15: Add custom values to the metadata [#61](https://github.com/paritytech/frame-metadata/pull/61) 66 | - v15/metadata: Add outer enum types for calls, events, errors [#57](https://github.com/paritytech/frame-metadata/pull/57) 67 | - Metadata V15: Enrich extrinsic type info for decoding [#56](https://github.com/paritytech/frame-metadata/pull/56) 68 | 69 | ### Changed 70 | 71 | - Simplify feature-flag and use common types [#62](https://github.com/paritytech/frame-metadata/pull/62) 72 | - v15: Rename `error_enum_ty` to `module_error_enum_ty` [#60](https://github.com/paritytech/frame-metadata/pull/60) 73 | 74 | ## [15.1.0] - 2023-03-30 75 | 76 | ### Added 77 | 78 | - Add metadata V15 with Runtime API support [#48](https://github.com/paritytech/frame-metadata/pull/48) 79 | 80 | ## [15.0.0] - 2022-02-08 81 | 82 | ### Changed 83 | 84 | - Update edition to 2021 85 | - Update `scale-info` to v2.0.0 and `parity-scale-codec` to v3.0.0 [#35](https://github.com/paritytech/frame-metadata/pull/35) 86 | 87 | ## [14.2.0] - 2021-11-04 88 | 89 | - Add function to return metadata version [#30](https://github.com/paritytech/frame-metadata/pull/30) 90 | 91 | ## [14.1.0] - 2021-11-03 92 | 93 | - Add metadata version v8-v11 [#28](https://github.com/paritytech/frame-metadata/pull/28) 94 | - Combine Map/NMap/DoubleMap StorageEntryTypes [#23](https://github.com/paritytech/frame-metadata/pull/23) 95 | 96 | ## [14.0.0] - 2021-09-01 97 | 98 | ## [14.0.0-rc.3] - 2021-08-31 99 | 100 | ### Added 101 | 102 | - Add Runtime type to metadata 103 | 104 | ## [14.0.0-rc.2] - 2021-08-04 105 | 106 | ### Changed 107 | 108 | Combine Map/NMap/DoubleMap StorageEntryTypes [#23](https://github.com/paritytech/frame-metadata/pull/23) 109 | 110 | ## [14.0.0-rc.1] - 2021-07-30 111 | 112 | ### Added 113 | 114 | - Metadata V14 115 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "frame-metadata" 4 | ] 5 | -------------------------------------------------------------------------------- /LICENSE-APACHE2: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | NOTE 204 | 205 | Individual files contain the following tag instead of the full license 206 | text. 207 | 208 | SPDX-License-Identifier: Apache-2.0 209 | 210 | This enables machine processing of license information based on the SPDX 211 | License Identifiers that are here available: http://spdx.org/licenses/ -------------------------------------------------------------------------------- /LICENSE-GPL3: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | "CLASSPATH" EXCEPTION TO THE GPL 677 | 678 | Linking this library statically or dynamically with other modules is making 679 | a combined work based on this library. Thus, the terms and conditions of the 680 | GNU General Public License cover the whole combination. 681 | 682 | As a special exception, the copyright holders of this library give you 683 | permission to link this library with independent modules to produce an 684 | executable, regardless of the license terms of these independent modules, 685 | and to copy and distribute the resulting executable under terms of your 686 | choice, provided that you also meet, for each linked independent module, 687 | the terms and conditions of the license of that module. An independent 688 | module is a module which is not derived from or based on this library. 689 | If you modify this library, you may extend this exception to your version 690 | of the library, but you are not obligated to do so. If you do not wish to 691 | do so, delete this exception statement from your version. 692 | 693 | NOTE 694 | 695 | Individual files contain the following tag instead of the full license text. 696 | 697 | SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 698 | 699 | This enables machine processing of license information based on the SPDX 700 | License Identifiers that are here available: http://spdx.org/licenses/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # frame-metadata 2 | 3 | Defines FRAME metadata types for [Substrate](https://github.com/paritytech/substrate) runtimes. 4 | 5 | Originally part of the `substrate` repository, it was extracted here as part of https://github.com/paritytech/substrate/pull/8615. 6 | 7 | ## Versioning 8 | 9 | Starting from `v8`, all historical metadata type definitions are retained. These can be enabled via features e.g. `v13`. The latest version is enabled by default. All legacy versions are available under the `legacy` feature. 10 | 11 | ### Tooling 12 | 13 | The intention is to provide tooling here in the future to handle the different versions of metadata. 14 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | # Release Checklist 2 | 3 | These steps assume that you've checked out the `frame-metadata` repository and are in the root directory of it. 4 | 5 | We also assume that ongoing work done is being merged directly to the `main` branch. 6 | 7 | 1. Ensure that everything you'd like to see released is on the `main` branch. 8 | 9 | 2. Create a release branch off `main`, for example `release-v14.3.0`. Decide how far the version needs to be bumped based 10 | on the changes to date. If unsure what to bump the version to (e.g. is it a major, minor or patch release), check with the 11 | Parity Tools team. 12 | 13 | 3. Check that you're happy with the current documentation. 14 | 15 | ```bash 16 | cargo doc --open --all-features 17 | ``` 18 | 19 | Optionally you can also confirm that any external links 20 | are still valid like so: 21 | 22 | ```bash 23 | cargo install cargo-deadlinks 24 | cargo deadlinks --check-http -- --all-features 25 | ``` 26 | 27 | If there are minor issues with the documentation, they can be fixed in the release branch. 28 | 29 | 4. Bump the crate version in `frame-metadata/Cargo.toml` to whatever was decided in step 2. 30 | 31 | 5. Update `CHANGELOG.md` to reflect the difference between this release and the last. If you're unsure of 32 | what to add, check with the Tools team. See the `CHANGELOG.md` file for details of the format it follows. 33 | 34 | Any [closed PRs](https://github.com/paritytech/frame-metadata/pulls?q=is%3Apr+sort%3Aupdated-desc+is%3Aclosed) between the last release and 35 | this release branch should be noted. 36 | 37 | 6. Commit any of the above changes to the release branch and open a PR in GitHub with a base of `main`. 38 | 39 | 7. Once the branch has been reviewed and passes CI, merge it. 40 | 41 | 8. Now, we're ready to publish the release to crates.io. 42 | 43 | Checkout `main`, ensuring we're looking at that latest merge (`git pull`). 44 | 45 | ```bash 46 | cd frame-metadata && cargo publish 47 | ``` 48 | 49 | 9. If the release was successful, tag the commit that we released in the `main` branch with the 50 | version that we just released, for example: 51 | 52 | ```bash 53 | git tag -s v14.3.0 # use the version number you've just published to crates.io, not this one 54 | git push --tags 55 | ``` 56 | 57 | Once this is pushed, go along to [the releases page on GitHub](https://github.com/paritytech/frame-metadata/releases) 58 | and draft a new release which points to the tag you just pushed to `main` above. Copy the changelog comments 59 | for the current release into the release description. 60 | -------------------------------------------------------------------------------- /deny.toml: -------------------------------------------------------------------------------- 1 | # This template contains all of the possible sections and their default values 2 | 3 | # Note that all fields that take a lint level have these possible values: 4 | # * deny - An error will be produced and the check will fail 5 | # * warn - A warning will be produced, but the check will not fail 6 | # * allow - No warning or error will be produced, though in some cases a note will be 7 | 8 | # This section is considered when running `cargo deny check advisories` 9 | # More documentation for the advisories section can be found here: 10 | # https://github.com/EmbarkStudios/cargo-deny#the-advisories-section 11 | [advisories] 12 | # The path where the advisory database is cloned/fetched into 13 | db-path = "~/.cargo/advisory-db" 14 | # The url(s) of the advisory database to use 15 | db-urls = ["https://github.com/rustsec/advisory-db"] 16 | # A list of advisory IDs to ignore. Note that ignored advisories will still output 17 | # a note when they are encountered. 18 | ignore = [] 19 | # Threshold for security vulnerabilities, any vulnerability with a CVSS score 20 | # lower than the range specified will be ignored. Note that ignored advisories 21 | # will still output a note when they are encountered. 22 | # * None - CVSS Score 0.0 23 | # * Low - CVSS Score 0.1 - 3.9 24 | # * Medium - CVSS Score 4.0 - 6.9 25 | # * High - CVSS Score 7.0 - 8.9 26 | # * Critical - CVSS Score 9.0 - 10.0 27 | #severity-threshold = 28 | 29 | # This section is considered when running `cargo deny check licenses` 30 | # More documentation for the licenses section can be found here: 31 | # https://github.com/EmbarkStudios/cargo-deny#the-licenses-section 32 | [licenses] 33 | # List of explictly allowed licenses 34 | # See https://spdx.org/licenses/ for list of possible licenses 35 | # [possible values: any SPDX 3.7 short identifier (+ optional exception)]. 36 | allow = [ 37 | "MIT", 38 | "Apache-2.0", 39 | "Unicode-DFS-2016", 40 | "Zlib", 41 | "Unicode-3.0", 42 | ] 43 | # The confidence threshold for detecting a license from license text. 44 | # The higher the value, the more closely the license text must be to the 45 | # canonical license text of a valid SPDX license file. 46 | # [possible values: any between 0.0 and 1.0]. 47 | confidence-threshold = 0.8 48 | 49 | # This section is considered when running `cargo deny check bans`. 50 | # More documentation about the 'bans' section can be found here: 51 | # https://github.com/EmbarkStudios/cargo-deny#crate-bans-cargo-deny-check-ban 52 | [bans] 53 | # Lint level for when multiple versions of the same crate are detected 54 | multiple-versions = "warn" 55 | # The graph highlighting used when creating dotgraphs for crates 56 | # with multiple versions 57 | # * lowest-version - The path to the lowest versioned duplicate is highlighted 58 | # * simplest-path - The path to the version with the fewest edges is highlighted 59 | # * all - Both lowest-version and simplest-path are used 60 | highlight = "all" 61 | # List of crates that are allowed. Use with care! 62 | allow = [ 63 | #{ name = "ansi_term", version = "=0.11.0" }, 64 | ] 65 | # List of crates to deny 66 | deny = [ 67 | # Each entry the name of a crate and a version range. If version is 68 | # not specified, all versions will be matched. 69 | #{ name = "ansi_term", version = "=0.11.0" }, 70 | ] 71 | # Certain crates/versions that will be skipped when doing duplicate detection. 72 | skip = [ 73 | #{ name = "ansi_term", version = "=0.11.0" }, 74 | ] 75 | # Similarly to `skip` allows you to skip certain crates during duplicate detection, 76 | # unlike skip, it also includes the entire tree of transitive dependencies starting at 77 | # the specified crate, up to a certain depth, which is by default infinite 78 | skip-tree = [ 79 | #{ name = "ansi_term", version = "=0.11.0", depth = 20 }, 80 | ] 81 | 82 | 83 | # This section is considered when running `cargo deny check sources`. 84 | # More documentation about the 'sources' section can be found here: 85 | # https://github.com/EmbarkStudios/cargo-deny#crate-sources-cargo-deny-check-sources 86 | [sources] 87 | # Lint level for what to happen when a crate from a crate registry that is not in the allow list is encountered 88 | unknown-registry = "warn" 89 | # Lint level for what to happen when a crate from a git repository that is not in the allow list is encountered 90 | unknown-git = "warn" 91 | # List of URLs for allowed crate registries, by default https://github.com/rust-lang/crates.io-index is included 92 | #allow-registry = [] 93 | # List of URLs for allowed Git repositories 94 | allow-git = [] 95 | 96 | [graph] 97 | # If 1 or more target triples (and optionally, target_features) are specified, only 98 | # the specified targets will be checked when running `cargo deny check`. This means, 99 | # if a particular package is only ever used as a target specific dependency, such 100 | # as, for example, the `nix` crate only being used via the `target_family = "unix"` 101 | # configuration, that only having windows targets in this list would mean the nix 102 | # crate, as well as any of its exclusive dependencies not shared by any other 103 | # crates, would be ignored, as the target list here is effectively saying which 104 | # targets you are building for. 105 | targets = [ 106 | # The triple can be any string, but only the target triples built in to 107 | # rustc (as of 1.40) can be checked against actual config expressions 108 | #{ triple = "x86_64-unknown-linux-musl" }, 109 | # You can also specify which target_features you promise are enabled for a particular 110 | # target. target_features are currently not validated against the actual valid 111 | # features supported by the target architecture. 112 | #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, 113 | ] 114 | -------------------------------------------------------------------------------- /frame-metadata/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "frame-metadata" 3 | version = "23.0.0" 4 | authors = ["Parity Technologies "] 5 | edition = "2021" 6 | license = "Apache-2.0" 7 | homepage = "https://substrate.dev" 8 | repository = "https://github.com/paritytech/frame-metadata/" 9 | description = "Metadata types for Substrate runtimes" 10 | readme = "README.md" 11 | 12 | [package.metadata.docs.rs] 13 | targets = ["x86_64-unknown-linux-gnu"] 14 | 15 | [dependencies] 16 | codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } 17 | cfg-if = "1.0.0" 18 | scale-info = { version = "2.0.0", default-features = false, optional = true, features = ["derive"] } 19 | serde = { version = "1.0.101", default-features = false, optional = true, features = ["derive"] } 20 | 21 | [features] 22 | default = ["std", "current"] 23 | 24 | # Feature flag for pre-V14 versions. 25 | legacy = [] 26 | 27 | # The current stable metadata versions. 28 | current = ["scale-info"] 29 | 30 | # Unstable next metadata version. 31 | unstable = ["current"] 32 | 33 | # Serde support without relying on std features 34 | serde_full = [ 35 | "scale-info/serde", 36 | "codec/serde", 37 | "serde", 38 | "serde/alloc", 39 | ] 40 | 41 | # Scale decode support without relying on std features 42 | decode = ["scale-info/decode"] 43 | 44 | std = [ 45 | "decode", 46 | "serde_full", 47 | "codec/std", 48 | "scale-info/std", 49 | "serde/std", 50 | ] 51 | -------------------------------------------------------------------------------- /frame-metadata/README.md: -------------------------------------------------------------------------------- 1 | Decodable variant of the RuntimeMetadata. 2 | 3 | This really doesn't belong here, but is necessary for the moment. In the future 4 | it should be removed entirely to an external module for shimming on to the 5 | codec-encoded metadata. 6 | 7 | License: Apache-2.0 -------------------------------------------------------------------------------- /frame-metadata/src/decode_different.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | use codec::{Encode, Output}; 17 | 18 | cfg_if::cfg_if! { 19 | if #[cfg(feature = "std")] { 20 | use codec::{Decode, Error, Input}; 21 | /// On `std` the `StringBuf` used by [`DecodeDifferent`] is just a `String`. 22 | pub type StringBuf = String; 23 | } else { 24 | extern crate alloc; 25 | use alloc::vec::Vec; 26 | 27 | /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. 28 | /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. 29 | pub type StringBuf = &'static str; 30 | } 31 | } 32 | 33 | /// A type that decodes to a different type than it encodes. 34 | /// The user needs to make sure that both types use the same encoding. 35 | /// 36 | /// For example a `&'static [ &'static str ]` can be decoded to a `Vec`. 37 | #[derive(Clone)] 38 | pub enum DecodeDifferent 39 | where 40 | B: 'static, 41 | O: 'static, 42 | { 43 | /// Encodable variant of the value (doesn't need to be decodeable). 44 | Encode(B), 45 | /// Encodable & decodeable variant of the value. 46 | Decoded(O), 47 | } 48 | 49 | impl Encode for DecodeDifferent 50 | where 51 | B: Encode + 'static, 52 | O: Encode + 'static, 53 | { 54 | fn encode_to(&self, dest: &mut W) { 55 | match self { 56 | DecodeDifferent::Encode(b) => b.encode_to(dest), 57 | DecodeDifferent::Decoded(o) => o.encode_to(dest), 58 | } 59 | } 60 | } 61 | 62 | impl codec::EncodeLike for DecodeDifferent 63 | where 64 | B: Encode + 'static, 65 | O: Encode + 'static, 66 | { 67 | } 68 | 69 | #[cfg(feature = "std")] 70 | impl Decode for DecodeDifferent 71 | where 72 | B: 'static, 73 | O: Decode + 'static, 74 | { 75 | fn decode(input: &mut I) -> Result { 76 | ::decode(input).map(|val| DecodeDifferent::Decoded(val)) 77 | } 78 | } 79 | 80 | impl PartialEq for DecodeDifferent 81 | where 82 | B: Encode + Eq + PartialEq + 'static, 83 | O: Encode + Eq + PartialEq + 'static, 84 | { 85 | fn eq(&self, other: &Self) -> bool { 86 | self.encode() == other.encode() 87 | } 88 | } 89 | 90 | impl Eq for DecodeDifferent 91 | where 92 | B: Encode + Eq + PartialEq + 'static, 93 | O: Encode + Eq + PartialEq + 'static, 94 | { 95 | } 96 | 97 | impl core::fmt::Debug for DecodeDifferent 98 | where 99 | B: core::fmt::Debug + Eq + 'static, 100 | O: core::fmt::Debug + Eq + 'static, 101 | { 102 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 103 | match self { 104 | DecodeDifferent::Encode(b) => b.fmt(f), 105 | DecodeDifferent::Decoded(o) => o.fmt(f), 106 | } 107 | } 108 | } 109 | 110 | #[cfg(feature = "std")] 111 | impl serde::Serialize for DecodeDifferent 112 | where 113 | B: serde::Serialize + 'static, 114 | O: serde::Serialize + 'static, 115 | { 116 | fn serialize(&self, serializer: S) -> Result 117 | where 118 | S: serde::Serializer, 119 | { 120 | match self { 121 | DecodeDifferent::Encode(b) => b.serialize(serializer), 122 | DecodeDifferent::Decoded(o) => o.serialize(serializer), 123 | } 124 | } 125 | } 126 | 127 | /// An array type that decodes as a `Vec`. 128 | pub type DecodeDifferentArray = DecodeDifferent<&'static [B], Vec>; 129 | 130 | /// A string type that decodes as a [`StringBuf`]. 131 | pub type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>; 132 | 133 | /// Newtype wrapper for support encoding functions (actual the result of the function). 134 | #[derive(Clone, Eq)] 135 | pub struct FnEncode(pub fn() -> E) 136 | where 137 | E: Encode + 'static; 138 | 139 | impl Encode for FnEncode { 140 | fn encode_to(&self, dest: &mut W) { 141 | self.0().encode_to(dest); 142 | } 143 | } 144 | 145 | impl codec::EncodeLike for FnEncode {} 146 | 147 | impl PartialEq for FnEncode { 148 | fn eq(&self, other: &Self) -> bool { 149 | self.0().eq(&other.0()) 150 | } 151 | } 152 | 153 | impl core::fmt::Debug for FnEncode { 154 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 155 | self.0().fmt(f) 156 | } 157 | } 158 | 159 | #[cfg(feature = "std")] 160 | impl serde::Serialize for FnEncode { 161 | fn serialize(&self, serializer: S) -> Result 162 | where 163 | S: serde::Serializer, 164 | { 165 | self.0().serialize(serializer) 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /frame-metadata/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Decodable variant of the RuntimeMetadata. 17 | 18 | #![cfg_attr(not(feature = "std"), no_std)] 19 | #![warn(missing_docs)] 20 | #[cfg(all( 21 | any(feature = "decode", feature = "serde_full"), 22 | feature = "legacy", 23 | not(feature = "std") 24 | ))] 25 | compile_error!("decode and serde_full features prior to v14 require std"); 26 | 27 | #[cfg(feature = "serde_full")] 28 | use serde::{Deserialize, Serialize}; 29 | 30 | #[cfg(feature = "decode")] 31 | use codec::{Decode, Error, Input}; 32 | 33 | cfg_if::cfg_if! { 34 | if #[cfg(not(feature = "std"))] { 35 | extern crate alloc; 36 | use alloc::vec::Vec; 37 | } 38 | } 39 | 40 | use codec::{Encode, Output}; 41 | 42 | /// A type that decodes to a different type than it encodes. 43 | #[cfg(feature = "legacy")] 44 | pub mod decode_different; 45 | 46 | /// Metadata v8 47 | #[cfg(feature = "legacy")] 48 | pub mod v8; 49 | 50 | /// Metadata v9 51 | #[cfg(feature = "legacy")] 52 | pub mod v9; 53 | 54 | /// Metadata v10 55 | #[cfg(feature = "legacy")] 56 | pub mod v10; 57 | 58 | /// Metadata v11 59 | #[cfg(feature = "legacy")] 60 | pub mod v11; 61 | 62 | /// Metadata v12 63 | #[cfg(feature = "legacy")] 64 | pub mod v12; 65 | 66 | /// Metadata v13 67 | #[cfg(feature = "legacy")] 68 | pub mod v13; 69 | 70 | /// Metadata v14 71 | #[cfg(feature = "current")] 72 | pub mod v14; 73 | 74 | /// Metadata v15 75 | #[cfg(feature = "current")] 76 | pub mod v15; 77 | 78 | /// Metadata v16 79 | #[cfg(feature = "current")] 80 | pub mod v16; 81 | 82 | /// Metadata prefix. 83 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warning for endianness. 84 | 85 | /// Metadata prefixed by a u32 for reserved usage 86 | #[derive(Eq, Encode, PartialEq, Debug)] 87 | #[cfg_attr(feature = "decode", derive(Decode))] 88 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 89 | pub struct RuntimeMetadataPrefixed(pub u32, pub RuntimeMetadata); 90 | 91 | impl From for Vec { 92 | fn from(value: RuntimeMetadataPrefixed) -> Self { 93 | value.encode() 94 | } 95 | } 96 | 97 | /// The metadata of a runtime. 98 | /// The version ID encoded/decoded through 99 | /// the enum nature of `RuntimeMetadata`. 100 | #[derive(Eq, Encode, PartialEq, Debug)] 101 | #[cfg_attr(feature = "decode", derive(Decode))] 102 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 103 | pub enum RuntimeMetadata { 104 | /// Unused; enum filler. 105 | V0(RuntimeMetadataDeprecated), 106 | /// Version 1 for runtime metadata. No longer used. 107 | V1(RuntimeMetadataDeprecated), 108 | /// Version 2 for runtime metadata. No longer used. 109 | V2(RuntimeMetadataDeprecated), 110 | /// Version 3 for runtime metadata. No longer used. 111 | V3(RuntimeMetadataDeprecated), 112 | /// Version 4 for runtime metadata. No longer used. 113 | V4(RuntimeMetadataDeprecated), 114 | /// Version 5 for runtime metadata. No longer used. 115 | V5(RuntimeMetadataDeprecated), 116 | /// Version 6 for runtime metadata. No longer used. 117 | V6(RuntimeMetadataDeprecated), 118 | /// Version 7 for runtime metadata. No longer used. 119 | V7(RuntimeMetadataDeprecated), 120 | /// Version 8 for runtime metadata. 121 | #[cfg(feature = "legacy")] 122 | V8(v8::RuntimeMetadataV8), 123 | /// Version 8 for runtime metadata, as raw encoded bytes. 124 | #[cfg(not(feature = "legacy"))] 125 | V8(OpaqueMetadata), 126 | /// Version 9 for runtime metadata. 127 | #[cfg(feature = "legacy")] 128 | V9(v9::RuntimeMetadataV9), 129 | /// Version 9 for runtime metadata, as raw encoded bytes. 130 | #[cfg(not(feature = "legacy"))] 131 | V9(OpaqueMetadata), 132 | /// Version 10 for runtime metadata. 133 | #[cfg(feature = "legacy")] 134 | V10(v10::RuntimeMetadataV10), 135 | /// Version 10 for runtime metadata, as raw encoded bytes. 136 | #[cfg(not(feature = "legacy"))] 137 | V10(OpaqueMetadata), 138 | /// Version 11 for runtime metadata. 139 | #[cfg(feature = "legacy")] 140 | V11(v11::RuntimeMetadataV11), 141 | /// Version 11 for runtime metadata, as raw encoded bytes. 142 | #[cfg(not(feature = "legacy"))] 143 | V11(OpaqueMetadata), 144 | /// Version 12 for runtime metadata 145 | #[cfg(feature = "legacy")] 146 | V12(v12::RuntimeMetadataV12), 147 | /// Version 12 for runtime metadata, as raw encoded bytes. 148 | #[cfg(not(feature = "legacy"))] 149 | V12(OpaqueMetadata), 150 | /// Version 13 for runtime metadata. 151 | #[cfg(feature = "legacy")] 152 | V13(v13::RuntimeMetadataV13), 153 | /// Version 13 for runtime metadata, as raw encoded bytes. 154 | #[cfg(not(feature = "legacy"))] 155 | V13(OpaqueMetadata), 156 | /// Version 14 for runtime metadata. 157 | #[cfg(feature = "current")] 158 | V14(v14::RuntimeMetadataV14), 159 | /// Version 14 for runtime metadata, as raw encoded bytes. 160 | #[cfg(not(feature = "current"))] 161 | V14(OpaqueMetadata), 162 | /// Version 15 for runtime metadata. 163 | #[cfg(feature = "current")] 164 | V15(v15::RuntimeMetadataV15), 165 | /// Version 15 for runtime metadata, as raw encoded bytes. 166 | #[cfg(not(feature = "current"))] 167 | V15(OpaqueMetadata), 168 | /// Version 16 for runtime metadata. 169 | #[cfg(feature = "current")] 170 | V16(v16::RuntimeMetadataV16), 171 | /// Version 16 for runtime metadata, as raw encoded bytes. 172 | #[cfg(not(feature = "current"))] 173 | V16(OpaqueMetadata), 174 | } 175 | 176 | impl RuntimeMetadata { 177 | /// Get the version number of the metadata. 178 | pub fn version(&self) -> u32 { 179 | match self { 180 | RuntimeMetadata::V0(_) => 0, 181 | RuntimeMetadata::V1(_) => 1, 182 | RuntimeMetadata::V2(_) => 2, 183 | RuntimeMetadata::V3(_) => 3, 184 | RuntimeMetadata::V4(_) => 4, 185 | RuntimeMetadata::V5(_) => 5, 186 | RuntimeMetadata::V6(_) => 6, 187 | RuntimeMetadata::V7(_) => 7, 188 | RuntimeMetadata::V8(_) => 8, 189 | RuntimeMetadata::V9(_) => 9, 190 | RuntimeMetadata::V10(_) => 10, 191 | RuntimeMetadata::V11(_) => 11, 192 | RuntimeMetadata::V12(_) => 12, 193 | RuntimeMetadata::V13(_) => 13, 194 | RuntimeMetadata::V14(_) => 14, 195 | RuntimeMetadata::V15(_) => 15, 196 | RuntimeMetadata::V16(_) => 16, 197 | } 198 | } 199 | } 200 | 201 | /// Stores the encoded `RuntimeMetadata` as raw bytes. 202 | #[derive(Encode, Eq, PartialEq, Debug)] 203 | #[cfg_attr(feature = "decode", derive(Decode))] 204 | #[cfg_attr(feature = "serde_full", derive(Serialize, Deserialize))] 205 | pub struct OpaqueMetadata(pub Vec); 206 | 207 | /// Enum that should fail. 208 | #[derive(Eq, PartialEq, Debug)] 209 | #[cfg_attr(feature = "serde_full", derive(Serialize, Deserialize))] 210 | pub enum RuntimeMetadataDeprecated {} 211 | 212 | impl Encode for RuntimeMetadataDeprecated { 213 | fn encode_to(&self, _dest: &mut W) {} 214 | } 215 | 216 | impl codec::EncodeLike for RuntimeMetadataDeprecated {} 217 | 218 | #[cfg(feature = "decode")] 219 | impl Decode for RuntimeMetadataDeprecated { 220 | fn decode(_input: &mut I) -> Result { 221 | Err("Decoding is not supported".into()) 222 | } 223 | } 224 | 225 | #[cfg(test)] 226 | mod test { 227 | use super::*; 228 | use std::fs; 229 | 230 | fn load_metadata(version: u32) -> Vec { 231 | fs::read(format!("./test_data/ksm_metadata_v{}.bin", version)).unwrap() 232 | } 233 | 234 | #[test] 235 | fn should_decode_metadatav9() { 236 | let meta: RuntimeMetadataPrefixed = 237 | Decode::decode(&mut load_metadata(9).as_slice()).unwrap(); 238 | assert!(matches!(meta.1, RuntimeMetadata::V9(_))); 239 | } 240 | 241 | #[test] 242 | fn should_decode_metadatav10() { 243 | let meta: RuntimeMetadataPrefixed = 244 | Decode::decode(&mut load_metadata(10).as_slice()).unwrap(); 245 | assert!(matches!(meta.1, RuntimeMetadata::V10(_))); 246 | } 247 | 248 | #[test] 249 | fn should_decode_metadatav11() { 250 | let meta: RuntimeMetadataPrefixed = 251 | Decode::decode(&mut load_metadata(11).as_slice()).unwrap(); 252 | assert!(matches!(meta.1, RuntimeMetadata::V11(_))); 253 | } 254 | 255 | #[test] 256 | fn should_decode_metadatav12() { 257 | let meta: RuntimeMetadataPrefixed = 258 | Decode::decode(&mut load_metadata(12).as_slice()).unwrap(); 259 | assert!(matches!(meta.1, RuntimeMetadata::V12(_))); 260 | } 261 | 262 | #[test] 263 | fn should_decode_metadatav13() { 264 | let meta: RuntimeMetadataPrefixed = 265 | Decode::decode(&mut load_metadata(13).as_slice()).unwrap(); 266 | assert!(matches!(meta.1, RuntimeMetadata::V13(_))); 267 | } 268 | 269 | #[test] 270 | fn should_decode_metadatav14() { 271 | let meta: RuntimeMetadataPrefixed = 272 | Decode::decode(&mut load_metadata(14).as_slice()).unwrap(); 273 | assert!(matches!(meta.1, RuntimeMetadata::V14(_))); 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /frame-metadata/src/v10.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Metadata Version 10. Networks like Kusama contain this version on-chain. 17 | //! Chains old enough to contain this metadata need a way to decode it. 18 | 19 | #![allow(missing_docs)] 20 | 21 | use crate::decode_different::*; 22 | use codec::{Encode, Output}; 23 | 24 | cfg_if::cfg_if! { 25 | if #[cfg(feature = "std")] { 26 | use codec::Decode; 27 | use serde::Serialize; 28 | 29 | type StringBuf = String; 30 | } else { 31 | extern crate alloc; 32 | use alloc::vec::Vec; 33 | 34 | /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. 35 | /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. 36 | type StringBuf = &'static str; 37 | } 38 | } 39 | 40 | /// Curent prefix of metadata 41 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 42 | 43 | /// All the metadata about a function. 44 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 45 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 46 | pub struct FunctionMetadata { 47 | pub name: DecodeDifferentStr, 48 | pub arguments: DecodeDifferentArray, 49 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 50 | } 51 | 52 | /// All the metadata about a function argument. 53 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 54 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 55 | pub struct FunctionArgumentMetadata { 56 | pub name: DecodeDifferentStr, 57 | pub ty: DecodeDifferentStr, 58 | } 59 | 60 | /// All the metadata about an outer event. 61 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 62 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 63 | pub struct OuterEventMetadata { 64 | pub name: DecodeDifferentStr, 65 | pub events: DecodeDifferentArray< 66 | (&'static str, FnEncode<&'static [EventMetadata]>), 67 | (StringBuf, Vec), 68 | >, 69 | } 70 | 71 | /// All the metadata about an event. 72 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 73 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 74 | pub struct EventMetadata { 75 | pub name: DecodeDifferentStr, 76 | pub arguments: DecodeDifferentArray<&'static str, StringBuf>, 77 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 78 | } 79 | 80 | /// All the metadata about one storage entry. 81 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 82 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 83 | pub struct StorageEntryMetadata { 84 | pub name: DecodeDifferentStr, 85 | pub modifier: StorageEntryModifier, 86 | pub ty: StorageEntryType, 87 | pub default: ByteGetter, 88 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 89 | } 90 | 91 | /// All the metadata about one module constant. 92 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 93 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 94 | pub struct ModuleConstantMetadata { 95 | pub name: DecodeDifferentStr, 96 | pub ty: DecodeDifferentStr, 97 | pub value: ByteGetter, 98 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 99 | } 100 | 101 | /// All the metadata about a module error. 102 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 103 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 104 | pub struct ErrorMetadata { 105 | pub name: DecodeDifferentStr, 106 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 107 | } 108 | 109 | /// All the metadata about errors in a module. 110 | pub trait ModuleErrorMetadata { 111 | fn metadata() -> &'static [ErrorMetadata]; 112 | } 113 | 114 | impl ModuleErrorMetadata for &'static str { 115 | fn metadata() -> &'static [ErrorMetadata] { 116 | &[] 117 | } 118 | } 119 | 120 | /// A technical trait to store lazy initiated vec value as static dyn pointer. 121 | pub trait DefaultByte: Send + Sync { 122 | fn default_byte(&self) -> Vec; 123 | } 124 | 125 | /// Wrapper over dyn pointer for accessing a cached once byte value. 126 | #[derive(Clone)] 127 | pub struct DefaultByteGetter(pub &'static dyn DefaultByte); 128 | 129 | /// Decode different for static lazy initiated byte value. 130 | pub type ByteGetter = DecodeDifferent>; 131 | 132 | impl Encode for DefaultByteGetter { 133 | fn encode_to(&self, dest: &mut W) { 134 | self.0.default_byte().encode_to(dest) 135 | } 136 | } 137 | 138 | impl codec::EncodeLike for DefaultByteGetter {} 139 | 140 | impl PartialEq for DefaultByteGetter { 141 | fn eq(&self, other: &DefaultByteGetter) -> bool { 142 | let left = self.0.default_byte(); 143 | let right = other.0.default_byte(); 144 | left.eq(&right) 145 | } 146 | } 147 | 148 | impl Eq for DefaultByteGetter {} 149 | 150 | #[cfg(feature = "std")] 151 | impl serde::Serialize for DefaultByteGetter { 152 | fn serialize(&self, serializer: S) -> Result 153 | where 154 | S: serde::Serializer, 155 | { 156 | self.0.default_byte().serialize(serializer) 157 | } 158 | } 159 | 160 | impl core::fmt::Debug for DefaultByteGetter { 161 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 162 | self.0.default_byte().fmt(f) 163 | } 164 | } 165 | 166 | /// Hasher used by storage maps 167 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 168 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 169 | pub enum StorageHasher { 170 | Blake2_128, 171 | Blake2_256, 172 | Blake2_128Concat, 173 | Twox128, 174 | Twox256, 175 | Twox64Concat, 176 | } 177 | 178 | /// A storage entry type. 179 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 180 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 181 | pub enum StorageEntryType { 182 | Plain(DecodeDifferentStr), 183 | Map { 184 | hasher: StorageHasher, 185 | key: DecodeDifferentStr, 186 | value: DecodeDifferentStr, 187 | is_linked: bool, 188 | }, 189 | DoubleMap { 190 | hasher: StorageHasher, 191 | key1: DecodeDifferentStr, 192 | key2: DecodeDifferentStr, 193 | value: DecodeDifferentStr, 194 | key2_hasher: StorageHasher, 195 | }, 196 | } 197 | 198 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 199 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 200 | /// 201 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 202 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 203 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 204 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 205 | pub enum StorageEntryModifier { 206 | Optional, 207 | Default, 208 | } 209 | 210 | /// All metadata of the storage. 211 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 212 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 213 | pub struct StorageMetadata { 214 | /// The common prefix used by all storage entries. 215 | pub prefix: DecodeDifferent<&'static str, StringBuf>, 216 | pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec>, 217 | } 218 | 219 | /// The metadata of a runtime. 220 | #[derive(Eq, Encode, PartialEq, Debug)] 221 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 222 | pub struct RuntimeMetadataV10 { 223 | pub modules: DecodeDifferentArray, 224 | } 225 | 226 | /// All metadata about an runtime module. 227 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 228 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 229 | pub struct ModuleMetadata { 230 | pub name: DecodeDifferentStr, 231 | pub storage: Option, StorageMetadata>>, 232 | pub calls: ODFnA, 233 | pub event: ODFnA, 234 | pub constants: DFnA, 235 | pub errors: DFnA, 236 | } 237 | 238 | type ODFnA = Option>; 239 | type DFnA = DecodeDifferent, Vec>; 240 | -------------------------------------------------------------------------------- /frame-metadata/src/v11.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Metadata Version 11. Networks like Kusama contain this version on-chain. 17 | //! Chains old enough to contain this metadata need a way to decode it. 18 | 19 | #![allow(missing_docs)] 20 | 21 | use crate::decode_different::*; 22 | use codec::{Encode, Output}; 23 | 24 | cfg_if::cfg_if! { 25 | if #[cfg(feature = "std")] { 26 | use codec::Decode; 27 | use serde::Serialize; 28 | 29 | type StringBuf = String; 30 | } else { 31 | extern crate alloc; 32 | use alloc::vec::Vec; 33 | 34 | /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. 35 | /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. 36 | type StringBuf = &'static str; 37 | } 38 | } 39 | 40 | /// Current prefix of metadata 41 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 42 | 43 | /// All the metadata about a function. 44 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 45 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 46 | pub struct FunctionMetadata { 47 | pub name: DecodeDifferentStr, 48 | pub arguments: DecodeDifferentArray, 49 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 50 | } 51 | 52 | /// All the metadata about a function argument. 53 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 54 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 55 | pub struct FunctionArgumentMetadata { 56 | pub name: DecodeDifferentStr, 57 | pub ty: DecodeDifferentStr, 58 | } 59 | 60 | /// All the metadata about an outer event. 61 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 62 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 63 | pub struct OuterEventMetadata { 64 | pub name: DecodeDifferentStr, 65 | pub events: DecodeDifferentArray< 66 | (&'static str, FnEncode<&'static [EventMetadata]>), 67 | (StringBuf, Vec), 68 | >, 69 | } 70 | 71 | /// All the metadata about an event. 72 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 73 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 74 | pub struct EventMetadata { 75 | pub name: DecodeDifferentStr, 76 | pub arguments: DecodeDifferentArray<&'static str, StringBuf>, 77 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 78 | } 79 | 80 | /// All the metadata about one storage entry. 81 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 82 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 83 | pub struct StorageEntryMetadata { 84 | pub name: DecodeDifferentStr, 85 | pub modifier: StorageEntryModifier, 86 | pub ty: StorageEntryType, 87 | pub default: ByteGetter, 88 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 89 | } 90 | 91 | /// All the metadata about one module constant. 92 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 93 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 94 | pub struct ModuleConstantMetadata { 95 | pub name: DecodeDifferentStr, 96 | pub ty: DecodeDifferentStr, 97 | pub value: ByteGetter, 98 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 99 | } 100 | 101 | /// All the metadata about a module error. 102 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 103 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 104 | pub struct ErrorMetadata { 105 | pub name: DecodeDifferentStr, 106 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 107 | } 108 | 109 | /// All the metadata about errors in a module. 110 | pub trait ModuleErrorMetadata { 111 | fn metadata() -> &'static [ErrorMetadata]; 112 | } 113 | 114 | impl ModuleErrorMetadata for &'static str { 115 | fn metadata() -> &'static [ErrorMetadata] { 116 | &[] 117 | } 118 | } 119 | 120 | /// A technical trait to store lazy initiated vec value as static dyn pointer. 121 | pub trait DefaultByte: Send + Sync { 122 | fn default_byte(&self) -> Vec; 123 | } 124 | 125 | /// Wrapper over dyn pointer for accessing a cached once byte value. 126 | #[derive(Clone)] 127 | pub struct DefaultByteGetter(pub &'static dyn DefaultByte); 128 | 129 | /// Decode different for static lazy initiated byte value. 130 | pub type ByteGetter = DecodeDifferent>; 131 | 132 | impl Encode for DefaultByteGetter { 133 | fn encode_to(&self, dest: &mut W) { 134 | self.0.default_byte().encode_to(dest) 135 | } 136 | } 137 | 138 | impl codec::EncodeLike for DefaultByteGetter {} 139 | 140 | impl PartialEq for DefaultByteGetter { 141 | fn eq(&self, other: &DefaultByteGetter) -> bool { 142 | let left = self.0.default_byte(); 143 | let right = other.0.default_byte(); 144 | left.eq(&right) 145 | } 146 | } 147 | 148 | impl Eq for DefaultByteGetter {} 149 | 150 | #[cfg(feature = "std")] 151 | impl serde::Serialize for DefaultByteGetter { 152 | fn serialize(&self, serializer: S) -> Result 153 | where 154 | S: serde::Serializer, 155 | { 156 | self.0.default_byte().serialize(serializer) 157 | } 158 | } 159 | 160 | impl core::fmt::Debug for DefaultByteGetter { 161 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 162 | self.0.default_byte().fmt(f) 163 | } 164 | } 165 | 166 | /// Hasher used by storage maps 167 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 168 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 169 | pub enum StorageHasher { 170 | Blake2_128, 171 | Blake2_256, 172 | Blake2_128Concat, 173 | Twox128, 174 | Twox256, 175 | Twox64Concat, 176 | Identity, 177 | } 178 | 179 | /// A storage entry type. 180 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 181 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 182 | pub enum StorageEntryType { 183 | Plain(DecodeDifferentStr), 184 | Map { 185 | hasher: StorageHasher, 186 | key: DecodeDifferentStr, 187 | value: DecodeDifferentStr, 188 | // is_linked flag previously, unused now to keep backwards compat 189 | unused: bool, 190 | }, 191 | DoubleMap { 192 | hasher: StorageHasher, 193 | key1: DecodeDifferentStr, 194 | key2: DecodeDifferentStr, 195 | value: DecodeDifferentStr, 196 | key2_hasher: StorageHasher, 197 | }, 198 | } 199 | 200 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 201 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 202 | /// 203 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 204 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 205 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 206 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 207 | pub enum StorageEntryModifier { 208 | Optional, 209 | Default, 210 | } 211 | 212 | /// All metadata of the storage. 213 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 214 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 215 | pub struct StorageMetadata { 216 | /// The common prefix used by all storage entries. 217 | pub prefix: DecodeDifferent<&'static str, StringBuf>, 218 | pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec>, 219 | } 220 | 221 | /// Metadata of the extrinsic used by the runtime. 222 | #[derive(Eq, Encode, PartialEq, Debug)] 223 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 224 | pub struct ExtrinsicMetadata { 225 | /// Extrinsic version. 226 | pub version: u8, 227 | /// The signed extensions in the order they appear in the extrinsic. 228 | pub signed_extensions: Vec, 229 | } 230 | 231 | /// The metadata of a runtime. 232 | #[derive(Eq, Encode, PartialEq, Debug)] 233 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 234 | pub struct RuntimeMetadataV11 { 235 | /// Metadata of all the modules. 236 | pub modules: DecodeDifferentArray, 237 | /// Metadata of the extrinsic. 238 | pub extrinsic: ExtrinsicMetadata, 239 | } 240 | 241 | /// All metadata about an runtime module. 242 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 243 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 244 | pub struct ModuleMetadata { 245 | pub name: DecodeDifferentStr, 246 | pub storage: Option, StorageMetadata>>, 247 | pub calls: ODFnA, 248 | pub event: ODFnA, 249 | pub constants: DFnA, 250 | pub errors: DFnA, 251 | } 252 | 253 | type ODFnA = Option>; 254 | type DFnA = DecodeDifferent, Vec>; 255 | -------------------------------------------------------------------------------- /frame-metadata/src/v12.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Metadata Version 12. Networks like Kusama contain this version on-chain. 17 | //! Chains old enough to contain this metadata need a way to decode it. 18 | 19 | #![allow(missing_docs)] 20 | 21 | use crate::decode_different::*; 22 | use codec::{Encode, Output}; 23 | 24 | cfg_if::cfg_if! { 25 | if #[cfg(feature = "std")] { 26 | use codec::Decode; 27 | use serde::Serialize; 28 | 29 | type StringBuf = String; 30 | } else { 31 | extern crate alloc; 32 | use alloc::vec::Vec; 33 | 34 | /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. 35 | /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. 36 | type StringBuf = &'static str; 37 | } 38 | } 39 | 40 | /// Current prefix of metadata 41 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 42 | 43 | /// Metadata about a function. 44 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 45 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 46 | pub struct FunctionMetadata { 47 | pub name: DecodeDifferentStr, 48 | pub arguments: DecodeDifferentArray, 49 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 50 | } 51 | 52 | /// Metadata about a function argument. 53 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 54 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 55 | pub struct FunctionArgumentMetadata { 56 | pub name: DecodeDifferentStr, 57 | pub ty: DecodeDifferentStr, 58 | } 59 | 60 | /// Metadata about an outer event. 61 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 62 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 63 | pub struct OuterEventMetadata { 64 | pub name: DecodeDifferentStr, 65 | pub events: DecodeDifferentArray< 66 | (&'static str, FnEncode<&'static [EventMetadata]>), 67 | (StringBuf, Vec), 68 | >, 69 | } 70 | 71 | /// Metadata about an event. 72 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 73 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 74 | pub struct EventMetadata { 75 | pub name: DecodeDifferentStr, 76 | pub arguments: DecodeDifferentArray<&'static str, StringBuf>, 77 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 78 | } 79 | 80 | /// Metadata about one storage entry. 81 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 82 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 83 | pub struct StorageEntryMetadata { 84 | pub name: DecodeDifferentStr, 85 | pub modifier: StorageEntryModifier, 86 | pub ty: StorageEntryType, 87 | pub default: ByteGetter, 88 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 89 | } 90 | 91 | /// Metadata about one module constant. 92 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 93 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 94 | pub struct ModuleConstantMetadata { 95 | pub name: DecodeDifferentStr, 96 | pub ty: DecodeDifferentStr, 97 | pub value: ByteGetter, 98 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 99 | } 100 | 101 | /// Metadata about a module error. 102 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 103 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 104 | pub struct ErrorMetadata { 105 | pub name: DecodeDifferentStr, 106 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 107 | } 108 | 109 | /// Metadata about errors in a module. 110 | pub trait ModuleErrorMetadata { 111 | fn metadata() -> &'static [ErrorMetadata]; 112 | } 113 | 114 | impl ModuleErrorMetadata for &'static str { 115 | fn metadata() -> &'static [ErrorMetadata] { 116 | &[] 117 | } 118 | } 119 | 120 | /// A technical trait to store lazy initiated vec value as static dyn pointer. 121 | pub trait DefaultByte: Send + Sync { 122 | fn default_byte(&self) -> Vec; 123 | } 124 | 125 | /// Wrapper over dyn pointer for accessing a cached once byte value. 126 | #[derive(Clone)] 127 | pub struct DefaultByteGetter(pub &'static dyn DefaultByte); 128 | 129 | /// Decode different for static lazy initiated byte value. 130 | pub type ByteGetter = DecodeDifferent>; 131 | 132 | impl Encode for DefaultByteGetter { 133 | fn encode_to(&self, dest: &mut W) { 134 | self.0.default_byte().encode_to(dest) 135 | } 136 | } 137 | 138 | impl codec::EncodeLike for DefaultByteGetter {} 139 | 140 | impl PartialEq for DefaultByteGetter { 141 | fn eq(&self, other: &DefaultByteGetter) -> bool { 142 | let left = self.0.default_byte(); 143 | let right = other.0.default_byte(); 144 | left.eq(&right) 145 | } 146 | } 147 | 148 | impl Eq for DefaultByteGetter {} 149 | 150 | #[cfg(feature = "std")] 151 | impl serde::Serialize for DefaultByteGetter { 152 | fn serialize(&self, serializer: S) -> Result 153 | where 154 | S: serde::Serializer, 155 | { 156 | self.0.default_byte().serialize(serializer) 157 | } 158 | } 159 | 160 | impl core::fmt::Debug for DefaultByteGetter { 161 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 162 | self.0.default_byte().fmt(f) 163 | } 164 | } 165 | 166 | /// Hasher used by storage maps 167 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 168 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 169 | pub enum StorageHasher { 170 | Blake2_128, 171 | Blake2_256, 172 | Blake2_128Concat, 173 | Twox128, 174 | Twox256, 175 | Twox64Concat, 176 | Identity, 177 | } 178 | 179 | /// A storage entry type. 180 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 181 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 182 | pub enum StorageEntryType { 183 | Plain(DecodeDifferentStr), 184 | Map { 185 | hasher: StorageHasher, 186 | key: DecodeDifferentStr, 187 | value: DecodeDifferentStr, 188 | // is_linked flag previously, unused now to keep backwards compat 189 | unused: bool, 190 | }, 191 | DoubleMap { 192 | hasher: StorageHasher, 193 | key1: DecodeDifferentStr, 194 | key2: DecodeDifferentStr, 195 | value: DecodeDifferentStr, 196 | key2_hasher: StorageHasher, 197 | }, 198 | } 199 | 200 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 201 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 202 | /// 203 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 204 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 205 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 206 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 207 | pub enum StorageEntryModifier { 208 | Optional, 209 | Default, 210 | } 211 | 212 | /// All metadata of the storage. 213 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 214 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 215 | pub struct StorageMetadata { 216 | /// The common prefix used by all storage entries. 217 | pub prefix: DecodeDifferent<&'static str, StringBuf>, 218 | pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec>, 219 | } 220 | 221 | /// Metadata of the extrinsic used by the runtime. 222 | #[derive(Eq, Encode, PartialEq, Debug)] 223 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 224 | pub struct ExtrinsicMetadata { 225 | /// Extrinsic version. 226 | pub version: u8, 227 | /// The signed extensions in the order they appear in the extrinsic. 228 | pub signed_extensions: Vec, 229 | } 230 | 231 | /// The metadata of a runtime. 232 | #[derive(Eq, Encode, PartialEq, Debug)] 233 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 234 | pub struct RuntimeMetadataV12 { 235 | /// Metadata of all the modules. 236 | pub modules: DecodeDifferentArray, 237 | /// Metadata of the extrinsic. 238 | pub extrinsic: ExtrinsicMetadata, 239 | } 240 | 241 | /// All metadata about an runtime module. 242 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 243 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 244 | pub struct ModuleMetadata { 245 | pub name: DecodeDifferentStr, 246 | pub storage: Option, StorageMetadata>>, 247 | pub calls: ODFnA, 248 | pub event: ODFnA, 249 | pub constants: DFnA, 250 | pub errors: DFnA, 251 | /// Define the index of the module, this index will be used for the encoding of module event, 252 | /// call and origin variants. 253 | pub index: u8, 254 | } 255 | 256 | type ODFnA = Option>; 257 | type DFnA = DecodeDifferent, Vec>; 258 | -------------------------------------------------------------------------------- /frame-metadata/src/v13.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) 2018-2021 Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Metadata Version 13. Networks like Kusama contain this version on-chain. 19 | //! Chains old enough to contain this metadata need a way to decode it. 20 | 21 | use crate::decode_different::*; 22 | use codec::{Encode, Output}; 23 | 24 | cfg_if::cfg_if! { 25 | if #[cfg(feature = "std")] { 26 | use codec::Decode; 27 | use serde::Serialize; 28 | } else { 29 | extern crate alloc; 30 | use alloc::vec::Vec; 31 | } 32 | } 33 | 34 | /// Current prefix of metadata 35 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 36 | 37 | /// Metadata about a function. 38 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 39 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 40 | pub struct FunctionMetadata { 41 | /// Function name. 42 | pub name: DecodeDifferentStr, 43 | /// A list of arguments this function takes. 44 | pub arguments: DecodeDifferentArray, 45 | /// Function documentation. 46 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 47 | } 48 | 49 | /// Metadata about a function argument. 50 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 51 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 52 | pub struct FunctionArgumentMetadata { 53 | /// Name of the variable for the argument. 54 | pub name: DecodeDifferentStr, 55 | /// Type of the parameter. 56 | pub ty: DecodeDifferentStr, 57 | } 58 | 59 | /// Metadata about an outer event. 60 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 61 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 62 | pub struct OuterEventMetadata { 63 | /// Name of the event. 64 | pub name: DecodeDifferentStr, 65 | /// A list of event details. 66 | pub events: DecodeDifferentArray< 67 | (&'static str, FnEncode<&'static [EventMetadata]>), 68 | (StringBuf, Vec), 69 | >, 70 | } 71 | 72 | /// Metadata about an event. 73 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 74 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 75 | pub struct EventMetadata { 76 | /// Name of the event. 77 | pub name: DecodeDifferentStr, 78 | /// Arguments of the event. 79 | pub arguments: DecodeDifferentArray<&'static str, StringBuf>, 80 | /// Documentation of the event. 81 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 82 | } 83 | 84 | /// Metadata about one storage entry. 85 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 86 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 87 | pub struct StorageEntryMetadata { 88 | /// Variable name of the storage entry. 89 | pub name: DecodeDifferentStr, 90 | /// A storage modifier of the storage entry (is it optional? does it have a default value?). 91 | pub modifier: StorageEntryModifier, 92 | /// Type of the value stored in the entry. 93 | pub ty: StorageEntryType, 94 | /// Default value (SCALE encoded). 95 | pub default: ByteGetter, 96 | /// Storage entry documentation. 97 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 98 | } 99 | 100 | /// Metadata about a module constant. 101 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 102 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 103 | pub struct ModuleConstantMetadata { 104 | /// Name of the module constant. 105 | pub name: DecodeDifferentStr, 106 | /// Type of the module constant. 107 | pub ty: DecodeDifferentStr, 108 | /// Value stored in the constant (SCALE encoded). 109 | pub value: ByteGetter, 110 | /// Documentation of the constant. 111 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 112 | } 113 | 114 | /// Metadata about a module error. 115 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 116 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 117 | pub struct ErrorMetadata { 118 | /// Name of the error. 119 | pub name: DecodeDifferentStr, 120 | /// Error variant documentation. 121 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 122 | } 123 | 124 | /// Metadata about errors in a module. 125 | pub trait ModuleErrorMetadata { 126 | /// Returns the error metadata. 127 | fn metadata() -> &'static [ErrorMetadata]; 128 | } 129 | 130 | impl ModuleErrorMetadata for &'static str { 131 | fn metadata() -> &'static [ErrorMetadata] { 132 | &[] 133 | } 134 | } 135 | 136 | /// A technical trait to store lazy initiated vec value as static dyn pointer. 137 | pub trait DefaultByte: Send + Sync { 138 | /// A default value (SCALE encoded). 139 | fn default_byte(&self) -> Vec; 140 | } 141 | 142 | /// Wrapper over dyn pointer for accessing a cached once byte value. 143 | #[derive(Clone)] 144 | pub struct DefaultByteGetter(pub &'static dyn DefaultByte); 145 | 146 | /// Decode different for static lazy initiated byte value. 147 | pub type ByteGetter = DecodeDifferent>; 148 | 149 | impl Encode for DefaultByteGetter { 150 | fn encode_to(&self, dest: &mut W) { 151 | self.0.default_byte().encode_to(dest) 152 | } 153 | } 154 | 155 | impl codec::EncodeLike for DefaultByteGetter {} 156 | 157 | impl PartialEq for DefaultByteGetter { 158 | fn eq(&self, other: &DefaultByteGetter) -> bool { 159 | let left = self.0.default_byte(); 160 | let right = other.0.default_byte(); 161 | left.eq(&right) 162 | } 163 | } 164 | 165 | impl Eq for DefaultByteGetter {} 166 | 167 | #[cfg(feature = "std")] 168 | impl serde::Serialize for DefaultByteGetter { 169 | fn serialize(&self, serializer: S) -> Result 170 | where 171 | S: serde::Serializer, 172 | { 173 | self.0.default_byte().serialize(serializer) 174 | } 175 | } 176 | 177 | impl core::fmt::Debug for DefaultByteGetter { 178 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 179 | self.0.default_byte().fmt(f) 180 | } 181 | } 182 | 183 | /// Hasher used by storage maps 184 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 185 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 186 | pub enum StorageHasher { 187 | /// 128-bit Blake2 hash. 188 | Blake2_128, 189 | /// 256-bit Blake2 hash. 190 | Blake2_256, 191 | /// Multiple 128-bit Blake2 hashes concatenated. 192 | Blake2_128Concat, 193 | /// 128-bit XX hash. 194 | Twox128, 195 | /// 256-bit XX hash. 196 | Twox256, 197 | /// Multiple 64-bit XX hashes concatenated. 198 | Twox64Concat, 199 | /// Identity hashing (no hashing). 200 | Identity, 201 | } 202 | 203 | /// A storage entry type. 204 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 205 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 206 | pub enum StorageEntryType { 207 | /// Plain storage entry (just the value). 208 | Plain(DecodeDifferentStr), 209 | /// A storage map. 210 | Map { 211 | /// Hasher type for the keys. 212 | hasher: StorageHasher, 213 | /// Key type. 214 | key: DecodeDifferentStr, 215 | /// Value type. 216 | value: DecodeDifferentStr, 217 | /// is_linked flag previously, unused now to keep backwards compat 218 | unused: bool, 219 | }, 220 | /// Storage Double Map. 221 | DoubleMap { 222 | /// Hasher type for the keys. 223 | hasher: StorageHasher, 224 | /// First key type. 225 | key1: DecodeDifferentStr, 226 | /// Second key type. 227 | key2: DecodeDifferentStr, 228 | /// Value type. 229 | value: DecodeDifferentStr, 230 | /// Hasher for the second key. 231 | key2_hasher: StorageHasher, 232 | }, 233 | /// Storage multi map. 234 | NMap { 235 | /// Key types. 236 | keys: DecodeDifferentArray<&'static str, StringBuf>, 237 | /// Key hashers. 238 | hashers: DecodeDifferentArray, 239 | /// Value type. 240 | value: DecodeDifferentStr, 241 | }, 242 | } 243 | 244 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 245 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 246 | /// 247 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 248 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 249 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 250 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 251 | pub enum StorageEntryModifier { 252 | /// The storage entry returns an `Option`, with `None` if the key is not present. 253 | Optional, 254 | /// The storage entry returns `T::Default` if the key is not present. 255 | Default, 256 | } 257 | 258 | /// All metadata of the storage. 259 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 260 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 261 | pub struct StorageMetadata { 262 | /// The common prefix used by all storage entries. 263 | pub prefix: DecodeDifferent<&'static str, StringBuf>, 264 | /// Storage entries. 265 | pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec>, 266 | } 267 | 268 | /// Metadata of the extrinsic used by the runtime. 269 | #[derive(Eq, Encode, PartialEq, Debug)] 270 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 271 | pub struct ExtrinsicMetadata { 272 | /// Extrinsic version. 273 | pub version: u8, 274 | /// The signed extensions in the order they appear in the extrinsic. 275 | pub signed_extensions: Vec, 276 | } 277 | 278 | /// The metadata of a runtime. 279 | #[derive(Eq, Encode, PartialEq, Debug)] 280 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 281 | pub struct RuntimeMetadataV13 { 282 | /// Metadata of all the modules. 283 | pub modules: DecodeDifferentArray, 284 | /// Metadata of the extrinsic. 285 | pub extrinsic: ExtrinsicMetadata, 286 | } 287 | 288 | /// All metadata about a runtime module. 289 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 290 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 291 | pub struct ModuleMetadata { 292 | /// Module name. 293 | pub name: DecodeDifferentStr, 294 | /// Module storage. 295 | pub storage: Option, StorageMetadata>>, 296 | /// Module calls. 297 | pub calls: ODFnA, 298 | /// Module Event type. 299 | pub event: ODFnA, 300 | /// Module constants. 301 | pub constants: DFnA, 302 | /// Module errors. 303 | pub errors: DFnA, 304 | /// Define the index of the module, this index will be used for the encoding of module event, 305 | /// call and origin variants. 306 | pub index: u8, 307 | } 308 | 309 | type ODFnA = Option>; 310 | type DFnA = DecodeDifferent, Vec>; 311 | -------------------------------------------------------------------------------- /frame-metadata/src/v14.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #[cfg(feature = "decode")] 17 | use codec::Decode; 18 | #[cfg(feature = "serde_full")] 19 | use serde::Serialize; 20 | 21 | use super::RuntimeMetadataPrefixed; 22 | use codec::Encode; 23 | use scale_info::prelude::vec::Vec; 24 | use scale_info::{ 25 | form::{Form, MetaForm, PortableForm}, 26 | IntoPortable, MetaType, PortableRegistry, Registry, 27 | }; 28 | 29 | /// Current prefix of metadata 30 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 31 | 32 | /// Latest runtime metadata 33 | pub type RuntimeMetadataLastVersion = RuntimeMetadataV14; 34 | 35 | impl From for super::RuntimeMetadataPrefixed { 36 | fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed { 37 | RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V14(metadata)) 38 | } 39 | } 40 | 41 | /// The metadata of a runtime. 42 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 43 | #[cfg_attr(feature = "decode", derive(Decode))] 44 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 45 | pub struct RuntimeMetadataV14 { 46 | /// Type registry containing all types used in the metadata. 47 | pub types: PortableRegistry, 48 | /// Metadata of all the pallets. 49 | pub pallets: Vec>, 50 | /// Metadata of the extrinsic. 51 | pub extrinsic: ExtrinsicMetadata, 52 | /// The type of the `Runtime`. 53 | pub ty: ::Type, 54 | } 55 | 56 | impl RuntimeMetadataV14 { 57 | /// Create a new instance of [`RuntimeMetadataV14`]. 58 | pub fn new( 59 | pallets: Vec, 60 | extrinsic: ExtrinsicMetadata, 61 | runtime_type: MetaType, 62 | ) -> Self { 63 | let mut registry = Registry::new(); 64 | let pallets = registry.map_into_portable(pallets); 65 | let extrinsic = extrinsic.into_portable(&mut registry); 66 | let ty = registry.register_type(&runtime_type); 67 | Self { 68 | types: registry.into(), 69 | pallets, 70 | extrinsic, 71 | ty, 72 | } 73 | } 74 | } 75 | 76 | /// Metadata of the extrinsic used by the runtime. 77 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 78 | #[cfg_attr(feature = "decode", derive(Decode))] 79 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 80 | #[cfg_attr( 81 | feature = "serde_full", 82 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 83 | )] 84 | pub struct ExtrinsicMetadata { 85 | /// The type of the extrinsic. 86 | pub ty: T::Type, 87 | /// Extrinsic version. 88 | pub version: u8, 89 | /// The signed extensions in the order they appear in the extrinsic. 90 | pub signed_extensions: Vec>, 91 | } 92 | 93 | impl IntoPortable for ExtrinsicMetadata { 94 | type Output = ExtrinsicMetadata; 95 | 96 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 97 | ExtrinsicMetadata { 98 | ty: registry.register_type(&self.ty), 99 | version: self.version, 100 | signed_extensions: registry.map_into_portable(self.signed_extensions), 101 | } 102 | } 103 | } 104 | 105 | /// Metadata of an extrinsic's signed extension. 106 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 107 | #[cfg_attr(feature = "decode", derive(Decode))] 108 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 109 | #[cfg_attr( 110 | feature = "serde_full", 111 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 112 | )] 113 | pub struct SignedExtensionMetadata { 114 | /// The unique signed extension identifier, which may be different from the type name. 115 | pub identifier: T::String, 116 | /// The type of the signed extension, with the data to be included in the extrinsic. 117 | pub ty: T::Type, 118 | /// The type of the additional signed data, with the data to be included in the signed payload 119 | pub additional_signed: T::Type, 120 | } 121 | 122 | impl IntoPortable for SignedExtensionMetadata { 123 | type Output = SignedExtensionMetadata; 124 | 125 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 126 | SignedExtensionMetadata { 127 | identifier: self.identifier.into_portable(registry), 128 | ty: registry.register_type(&self.ty), 129 | additional_signed: registry.register_type(&self.additional_signed), 130 | } 131 | } 132 | } 133 | 134 | /// All metadata about an runtime pallet. 135 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 136 | #[cfg_attr(feature = "decode", derive(Decode))] 137 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 138 | #[cfg_attr( 139 | feature = "serde_full", 140 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 141 | )] 142 | pub struct PalletMetadata { 143 | /// Pallet name. 144 | pub name: T::String, 145 | /// Pallet storage metadata. 146 | pub storage: Option>, 147 | /// Pallet calls metadata. 148 | pub calls: Option>, 149 | /// Pallet event metadata. 150 | pub event: Option>, 151 | /// Pallet constants metadata. 152 | pub constants: Vec>, 153 | /// Pallet error metadata. 154 | pub error: Option>, 155 | /// Define the index of the pallet, this index will be used for the encoding of pallet event, 156 | /// call and origin variants. 157 | pub index: u8, 158 | } 159 | 160 | impl IntoPortable for PalletMetadata { 161 | type Output = PalletMetadata; 162 | 163 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 164 | PalletMetadata { 165 | name: self.name.into_portable(registry), 166 | storage: self.storage.map(|storage| storage.into_portable(registry)), 167 | calls: self.calls.map(|calls| calls.into_portable(registry)), 168 | event: self.event.map(|event| event.into_portable(registry)), 169 | constants: registry.map_into_portable(self.constants), 170 | error: self.error.map(|error| error.into_portable(registry)), 171 | index: self.index, 172 | } 173 | } 174 | } 175 | 176 | /// All metadata of the pallet's storage. 177 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 178 | #[cfg_attr(feature = "decode", derive(Decode))] 179 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 180 | #[cfg_attr( 181 | feature = "serde_full", 182 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 183 | )] 184 | pub struct PalletStorageMetadata { 185 | /// The common prefix used by all storage entries. 186 | pub prefix: T::String, 187 | /// Metadata for all storage entries. 188 | pub entries: Vec>, 189 | } 190 | 191 | impl IntoPortable for PalletStorageMetadata { 192 | type Output = PalletStorageMetadata; 193 | 194 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 195 | PalletStorageMetadata { 196 | prefix: self.prefix.into_portable(registry), 197 | entries: registry.map_into_portable(self.entries), 198 | } 199 | } 200 | } 201 | 202 | /// Metadata about one storage entry. 203 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 204 | #[cfg_attr(feature = "decode", derive(Decode))] 205 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 206 | #[cfg_attr( 207 | feature = "serde_full", 208 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 209 | )] 210 | pub struct StorageEntryMetadata { 211 | /// Variable name of the storage entry. 212 | pub name: T::String, 213 | /// An `Option` modifier of that storage entry. 214 | pub modifier: StorageEntryModifier, 215 | /// Type of the value stored in the entry. 216 | pub ty: StorageEntryType, 217 | /// Default value (SCALE encoded). 218 | pub default: Vec, 219 | /// Storage entry documentation. 220 | pub docs: Vec, 221 | } 222 | 223 | impl IntoPortable for StorageEntryMetadata { 224 | type Output = StorageEntryMetadata; 225 | 226 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 227 | StorageEntryMetadata { 228 | name: self.name.into_portable(registry), 229 | modifier: self.modifier, 230 | ty: self.ty.into_portable(registry), 231 | default: self.default, 232 | docs: registry.map_into_portable(self.docs), 233 | } 234 | } 235 | } 236 | 237 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 238 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 239 | /// 240 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 241 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 242 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 243 | #[cfg_attr(feature = "decode", derive(Decode))] 244 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 245 | pub enum StorageEntryModifier { 246 | /// The storage entry returns an `Option`, with `None` if the key is not present. 247 | Optional, 248 | /// The storage entry returns `T::Default` if the key is not present. 249 | Default, 250 | } 251 | 252 | /// Hasher used by storage maps 253 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 254 | #[cfg_attr(feature = "decode", derive(Decode))] 255 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 256 | pub enum StorageHasher { 257 | /// 128-bit Blake2 hash. 258 | Blake2_128, 259 | /// 256-bit Blake2 hash. 260 | Blake2_256, 261 | /// Multiple 128-bit Blake2 hashes concatenated. 262 | Blake2_128Concat, 263 | /// 128-bit XX hash. 264 | Twox128, 265 | /// 256-bit XX hash. 266 | Twox256, 267 | /// Multiple 64-bit XX hashes concatenated. 268 | Twox64Concat, 269 | /// Identity hashing (no hashing). 270 | Identity, 271 | } 272 | 273 | /// A type of storage value. 274 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 275 | #[cfg_attr(feature = "decode", derive(Decode))] 276 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 277 | #[cfg_attr( 278 | feature = "serde_full", 279 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 280 | )] 281 | pub enum StorageEntryType { 282 | /// Plain storage entry (just the value). 283 | Plain(T::Type), 284 | /// A storage map. 285 | Map { 286 | /// One or more hashers, should be one hasher per key element. 287 | hashers: Vec, 288 | /// The type of the key, can be a tuple with elements for each of the hashers. 289 | key: T::Type, 290 | /// The type of the value. 291 | value: T::Type, 292 | }, 293 | } 294 | 295 | impl IntoPortable for StorageEntryType { 296 | type Output = StorageEntryType; 297 | 298 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 299 | match self { 300 | Self::Plain(plain) => StorageEntryType::Plain(registry.register_type(&plain)), 301 | Self::Map { 302 | hashers, 303 | key, 304 | value, 305 | } => StorageEntryType::Map { 306 | hashers, 307 | key: registry.register_type(&key), 308 | value: registry.register_type(&value), 309 | }, 310 | } 311 | } 312 | } 313 | 314 | /// Metadata for all calls in a pallet 315 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 316 | #[cfg_attr(feature = "decode", derive(Decode))] 317 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 318 | #[cfg_attr( 319 | feature = "serde_full", 320 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 321 | )] 322 | pub struct PalletCallMetadata { 323 | /// The corresponding enum type for the pallet call. 324 | pub ty: T::Type, 325 | } 326 | 327 | impl IntoPortable for PalletCallMetadata { 328 | type Output = PalletCallMetadata; 329 | 330 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 331 | PalletCallMetadata { 332 | ty: registry.register_type(&self.ty), 333 | } 334 | } 335 | } 336 | 337 | impl From for PalletCallMetadata { 338 | fn from(ty: MetaType) -> Self { 339 | Self { ty } 340 | } 341 | } 342 | 343 | /// Metadata about the pallet Event type. 344 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 345 | #[cfg_attr(feature = "decode", derive(Decode))] 346 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 347 | pub struct PalletEventMetadata { 348 | /// The Event type. 349 | pub ty: T::Type, 350 | } 351 | 352 | impl IntoPortable for PalletEventMetadata { 353 | type Output = PalletEventMetadata; 354 | 355 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 356 | PalletEventMetadata { 357 | ty: registry.register_type(&self.ty), 358 | } 359 | } 360 | } 361 | 362 | impl From for PalletEventMetadata { 363 | fn from(ty: MetaType) -> Self { 364 | Self { ty } 365 | } 366 | } 367 | 368 | /// Metadata about one pallet constant. 369 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 370 | #[cfg_attr(feature = "decode", derive(Decode))] 371 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 372 | #[cfg_attr( 373 | feature = "serde_full", 374 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 375 | )] 376 | pub struct PalletConstantMetadata { 377 | /// Name of the pallet constant. 378 | pub name: T::String, 379 | /// Type of the pallet constant. 380 | pub ty: T::Type, 381 | /// Value stored in the constant (SCALE encoded). 382 | pub value: Vec, 383 | /// Documentation of the constant. 384 | pub docs: Vec, 385 | } 386 | 387 | impl IntoPortable for PalletConstantMetadata { 388 | type Output = PalletConstantMetadata; 389 | 390 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 391 | PalletConstantMetadata { 392 | name: self.name.into_portable(registry), 393 | ty: registry.register_type(&self.ty), 394 | value: self.value, 395 | docs: registry.map_into_portable(self.docs), 396 | } 397 | } 398 | } 399 | 400 | /// Metadata about a pallet error. 401 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 402 | #[cfg_attr(feature = "decode", derive(Decode))] 403 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 404 | #[cfg_attr(feature = "serde_full", serde(bound(serialize = "T::Type: Serialize")))] 405 | pub struct PalletErrorMetadata { 406 | /// The error type information. 407 | pub ty: T::Type, 408 | } 409 | 410 | impl IntoPortable for PalletErrorMetadata { 411 | type Output = PalletErrorMetadata; 412 | 413 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 414 | PalletErrorMetadata { 415 | ty: registry.register_type(&self.ty), 416 | } 417 | } 418 | } 419 | 420 | impl From for PalletErrorMetadata { 421 | fn from(ty: MetaType) -> Self { 422 | Self { ty } 423 | } 424 | } 425 | -------------------------------------------------------------------------------- /frame-metadata/src/v15.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #[cfg(feature = "decode")] 17 | use codec::Decode; 18 | #[cfg(feature = "serde_full")] 19 | use serde::Serialize; 20 | 21 | use super::{RuntimeMetadataPrefixed, META_RESERVED}; 22 | use codec::Encode; 23 | use scale_info::{ 24 | form::{Form, MetaForm, PortableForm}, 25 | prelude::{collections::BTreeMap, vec::Vec}, 26 | IntoPortable, MetaType, PortableRegistry, Registry, 27 | }; 28 | 29 | pub use super::v14::{ 30 | PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, PalletEventMetadata, 31 | PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType, 32 | StorageHasher, 33 | }; 34 | 35 | /// Latest runtime metadata 36 | pub type RuntimeMetadataLastVersion = RuntimeMetadataV15; 37 | 38 | impl From for super::RuntimeMetadataPrefixed { 39 | fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed { 40 | RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V15(metadata)) 41 | } 42 | } 43 | 44 | /// The metadata of a runtime. 45 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 46 | #[cfg_attr(feature = "decode", derive(Decode))] 47 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 48 | pub struct RuntimeMetadataV15 { 49 | /// Type registry containing all types used in the metadata. 50 | pub types: PortableRegistry, 51 | /// Metadata of all the pallets. 52 | pub pallets: Vec>, 53 | /// Metadata of the extrinsic. 54 | pub extrinsic: ExtrinsicMetadata, 55 | /// The type of the `Runtime`. 56 | pub ty: ::Type, 57 | /// Metadata of the Runtime API. 58 | pub apis: Vec>, 59 | /// The outer enums types as found in the runtime. 60 | pub outer_enums: OuterEnums, 61 | /// Allows users to add custom types to the metadata. 62 | pub custom: CustomMetadata, 63 | } 64 | 65 | impl RuntimeMetadataV15 { 66 | /// Create a new instance of [`RuntimeMetadataV15`]. 67 | pub fn new( 68 | pallets: Vec, 69 | extrinsic: ExtrinsicMetadata, 70 | runtime_type: MetaType, 71 | apis: Vec, 72 | outer_enums: OuterEnums, 73 | custom: CustomMetadata, 74 | ) -> Self { 75 | let mut registry = Registry::new(); 76 | let pallets = registry.map_into_portable(pallets); 77 | let extrinsic = extrinsic.into_portable(&mut registry); 78 | let ty = registry.register_type(&runtime_type); 79 | let apis = registry.map_into_portable(apis); 80 | let outer_enums = outer_enums.into_portable(&mut registry); 81 | let custom = custom.into_portable(&mut registry); 82 | 83 | Self { 84 | types: registry.into(), 85 | pallets, 86 | extrinsic, 87 | ty, 88 | apis, 89 | outer_enums, 90 | custom, 91 | } 92 | } 93 | } 94 | 95 | /// Metadata of a runtime trait. 96 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 97 | #[cfg_attr(feature = "decode", derive(Decode))] 98 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 99 | #[cfg_attr( 100 | feature = "serde_full", 101 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 102 | )] 103 | pub struct RuntimeApiMetadata { 104 | /// Trait name. 105 | pub name: T::String, 106 | /// Trait methods. 107 | pub methods: Vec>, 108 | /// Trait documentation. 109 | pub docs: Vec, 110 | } 111 | 112 | impl IntoPortable for RuntimeApiMetadata { 113 | type Output = RuntimeApiMetadata; 114 | 115 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 116 | RuntimeApiMetadata { 117 | name: self.name.into_portable(registry), 118 | methods: registry.map_into_portable(self.methods), 119 | docs: registry.map_into_portable(self.docs), 120 | } 121 | } 122 | } 123 | 124 | /// Metadata of a runtime method. 125 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 126 | #[cfg_attr(feature = "decode", derive(Decode))] 127 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 128 | #[cfg_attr( 129 | feature = "serde_full", 130 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 131 | )] 132 | pub struct RuntimeApiMethodMetadata { 133 | /// Method name. 134 | pub name: T::String, 135 | /// Method parameters. 136 | pub inputs: Vec>, 137 | /// Method output. 138 | pub output: T::Type, 139 | /// Method documentation. 140 | pub docs: Vec, 141 | } 142 | 143 | impl IntoPortable for RuntimeApiMethodMetadata { 144 | type Output = RuntimeApiMethodMetadata; 145 | 146 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 147 | RuntimeApiMethodMetadata { 148 | name: self.name.into_portable(registry), 149 | inputs: registry.map_into_portable(self.inputs), 150 | output: registry.register_type(&self.output), 151 | docs: registry.map_into_portable(self.docs), 152 | } 153 | } 154 | } 155 | 156 | /// Metadata of a runtime method parameter. 157 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 158 | #[cfg_attr(feature = "decode", derive(Decode))] 159 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 160 | #[cfg_attr( 161 | feature = "serde_full", 162 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 163 | )] 164 | pub struct RuntimeApiMethodParamMetadata { 165 | /// Parameter name. 166 | pub name: T::String, 167 | /// Parameter type. 168 | pub ty: T::Type, 169 | } 170 | 171 | impl IntoPortable for RuntimeApiMethodParamMetadata { 172 | type Output = RuntimeApiMethodParamMetadata; 173 | 174 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 175 | RuntimeApiMethodParamMetadata { 176 | name: self.name.into_portable(registry), 177 | ty: registry.register_type(&self.ty), 178 | } 179 | } 180 | } 181 | 182 | /// Metadata of the extrinsic used by the runtime. 183 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 184 | #[cfg_attr(feature = "decode", derive(Decode))] 185 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 186 | #[cfg_attr( 187 | feature = "serde_full", 188 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 189 | )] 190 | pub struct ExtrinsicMetadata { 191 | /// Extrinsic version. 192 | pub version: u8, 193 | /// The type of the address that signes the extrinsic 194 | pub address_ty: T::Type, 195 | /// The type of the outermost Call enum. 196 | pub call_ty: T::Type, 197 | /// The type of the extrinsic's signature. 198 | pub signature_ty: T::Type, 199 | /// The type of the outermost Extra enum. 200 | pub extra_ty: T::Type, 201 | /// The signed extensions in the order they appear in the extrinsic. 202 | pub signed_extensions: Vec>, 203 | } 204 | 205 | impl IntoPortable for ExtrinsicMetadata { 206 | type Output = ExtrinsicMetadata; 207 | 208 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 209 | ExtrinsicMetadata { 210 | version: self.version, 211 | address_ty: registry.register_type(&self.address_ty), 212 | call_ty: registry.register_type(&self.call_ty), 213 | signature_ty: registry.register_type(&self.signature_ty), 214 | extra_ty: registry.register_type(&self.extra_ty), 215 | signed_extensions: registry.map_into_portable(self.signed_extensions), 216 | } 217 | } 218 | } 219 | 220 | /// Metadata of an extrinsic's signed extension. 221 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 222 | #[cfg_attr(feature = "decode", derive(Decode))] 223 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 224 | #[cfg_attr( 225 | feature = "serde_full", 226 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 227 | )] 228 | pub struct SignedExtensionMetadata { 229 | /// The unique signed extension identifier, which may be different from the type name. 230 | pub identifier: T::String, 231 | /// The type of the signed extension, with the data to be included in the extrinsic. 232 | pub ty: T::Type, 233 | /// The type of the additional signed data, with the data to be included in the signed payload 234 | pub additional_signed: T::Type, 235 | } 236 | 237 | impl IntoPortable for SignedExtensionMetadata { 238 | type Output = SignedExtensionMetadata; 239 | 240 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 241 | SignedExtensionMetadata { 242 | identifier: self.identifier.into_portable(registry), 243 | ty: registry.register_type(&self.ty), 244 | additional_signed: registry.register_type(&self.additional_signed), 245 | } 246 | } 247 | } 248 | 249 | /// All metadata about an runtime pallet. 250 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 251 | #[cfg_attr(feature = "decode", derive(Decode))] 252 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 253 | #[cfg_attr( 254 | feature = "serde_full", 255 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 256 | )] 257 | pub struct PalletMetadata { 258 | /// Pallet name. 259 | pub name: T::String, 260 | /// Pallet storage metadata. 261 | pub storage: Option>, 262 | /// Pallet calls metadata. 263 | pub calls: Option>, 264 | /// Pallet event metadata. 265 | pub event: Option>, 266 | /// Pallet constants metadata. 267 | pub constants: Vec>, 268 | /// Pallet error metadata. 269 | pub error: Option>, 270 | /// Define the index of the pallet, this index will be used for the encoding of pallet event, 271 | /// call and origin variants. 272 | pub index: u8, 273 | /// Pallet documentation. 274 | pub docs: Vec, 275 | } 276 | 277 | impl IntoPortable for PalletMetadata { 278 | type Output = PalletMetadata; 279 | 280 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 281 | PalletMetadata { 282 | name: self.name.into_portable(registry), 283 | storage: self.storage.map(|storage| storage.into_portable(registry)), 284 | calls: self.calls.map(|calls| calls.into_portable(registry)), 285 | event: self.event.map(|event| event.into_portable(registry)), 286 | constants: registry.map_into_portable(self.constants), 287 | error: self.error.map(|error| error.into_portable(registry)), 288 | index: self.index, 289 | docs: registry.map_into_portable(self.docs), 290 | } 291 | } 292 | } 293 | 294 | /// Metadata for custom types. 295 | /// 296 | /// This map associates a string key to a `CustomValueMetadata`. 297 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 298 | #[cfg_attr(feature = "decode", derive(Decode))] 299 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 300 | #[cfg_attr( 301 | feature = "serde_full", 302 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 303 | )] 304 | pub struct CustomMetadata { 305 | /// The custom map. 306 | pub map: BTreeMap>, 307 | } 308 | 309 | impl IntoPortable for CustomMetadata { 310 | type Output = CustomMetadata; 311 | 312 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 313 | let map = self 314 | .map 315 | .into_iter() 316 | .map(|(key, value)| (key.into_portable(registry), value.into_portable(registry))) 317 | .collect(); 318 | 319 | CustomMetadata { map } 320 | } 321 | } 322 | 323 | /// The associated value of a custom metadata type. 324 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 325 | #[cfg_attr(feature = "decode", derive(Decode))] 326 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 327 | #[cfg_attr( 328 | feature = "serde_full", 329 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 330 | )] 331 | pub struct CustomValueMetadata { 332 | /// The custom type. 333 | pub ty: T::Type, 334 | /// The custom value of this type. 335 | pub value: Vec, 336 | } 337 | 338 | impl IntoPortable for CustomValueMetadata { 339 | type Output = CustomValueMetadata; 340 | 341 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 342 | CustomValueMetadata { 343 | ty: registry.register_type(&self.ty), 344 | value: self.value, 345 | } 346 | } 347 | } 348 | 349 | /// The type of the outer enums. 350 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 351 | #[cfg_attr(feature = "decode", derive(Decode))] 352 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 353 | #[cfg_attr( 354 | feature = "serde_full", 355 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 356 | )] 357 | pub struct OuterEnums { 358 | /// The type of the outer `RuntimeCall` enum. 359 | pub call_enum_ty: T::Type, 360 | /// The type of the outer `RuntimeEvent` enum. 361 | pub event_enum_ty: T::Type, 362 | /// The module error type of the 363 | /// [`DispatchError::Module`](https://docs.rs/sp-runtime/24.0.0/sp_runtime/enum.DispatchError.html#variant.Module) variant. 364 | /// 365 | /// The `Module` variant will be 5 scale encoded bytes which are normally decoded into 366 | /// an `{ index: u8, error: [u8; 4] }` struct. This type ID points to an enum type which instead 367 | /// interprets the first `index` byte as a pallet variant, and the remaining `error` bytes as the 368 | /// appropriate `pallet::Error` type. It is an equally valid way to decode the error bytes, and 369 | /// can be more informative. 370 | /// 371 | /// # Note 372 | /// 373 | /// - This type cannot be used directly to decode `sp_runtime::DispatchError` from the 374 | /// chain. It provides just the information needed to decode `sp_runtime::DispatchError::Module`. 375 | /// - Decoding the 5 error bytes into this type will not always lead to all of the bytes being consumed; 376 | /// many error types do not require all of the bytes to represent them fully. 377 | pub error_enum_ty: T::Type, 378 | } 379 | 380 | impl IntoPortable for OuterEnums { 381 | type Output = OuterEnums; 382 | 383 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 384 | OuterEnums { 385 | call_enum_ty: registry.register_type(&self.call_enum_ty), 386 | event_enum_ty: registry.register_type(&self.event_enum_ty), 387 | error_enum_ty: registry.register_type(&self.error_enum_ty), 388 | } 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /frame-metadata/src/v16.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #[cfg(feature = "decode")] 17 | use codec::Decode; 18 | #[cfg(feature = "serde_full")] 19 | use serde::Serialize; 20 | 21 | use super::{RuntimeMetadataPrefixed, META_RESERVED}; 22 | use codec::{Compact, Encode}; 23 | use scale_info::{ 24 | form::{Form, MetaForm, PortableForm}, 25 | prelude::{collections::BTreeMap, vec::Vec}, 26 | IntoPortable, PortableRegistry, Registry, 27 | }; 28 | 29 | // These types have not changed, so we re-export from our v14/v15 definitions: 30 | pub use super::v14::{StorageEntryModifier, StorageEntryType, StorageHasher}; 31 | pub use super::v15::{CustomMetadata, CustomValueMetadata, OuterEnums}; 32 | 33 | /// The metadata for a method or function parameter. This is identical to 34 | /// [`crate::v15::RuntimeApiMethodParamMetadata`]. 35 | pub type FunctionParamMetadata = super::v15::RuntimeApiMethodParamMetadata; 36 | 37 | /// Latest runtime metadata. 38 | pub type RuntimeMetadataLastVersion = RuntimeMetadataV16; 39 | 40 | impl From for super::RuntimeMetadataPrefixed { 41 | fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed { 42 | RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V16(metadata)) 43 | } 44 | } 45 | 46 | /// The metadata of a runtime. 47 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 48 | #[cfg_attr(feature = "decode", derive(Decode))] 49 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 50 | pub struct RuntimeMetadataV16 { 51 | /// Type registry containing all types used in the metadata. 52 | pub types: PortableRegistry, 53 | /// Metadata of all the pallets. 54 | pub pallets: Vec>, 55 | /// Metadata of the extrinsic. 56 | pub extrinsic: ExtrinsicMetadata, 57 | /// Metadata of the Runtime API. 58 | pub apis: Vec>, 59 | /// The outer enums types as found in the runtime. 60 | pub outer_enums: OuterEnums, 61 | /// Allows users to add custom types to the metadata. 62 | pub custom: CustomMetadata, 63 | } 64 | 65 | impl RuntimeMetadataV16 { 66 | /// Create a new instance of [`RuntimeMetadataV16`]. 67 | pub fn new( 68 | pallets: Vec, 69 | extrinsic: ExtrinsicMetadata, 70 | apis: Vec, 71 | outer_enums: OuterEnums, 72 | custom: CustomMetadata, 73 | ) -> Self { 74 | let mut registry = Registry::new(); 75 | let pallets = registry.map_into_portable(pallets); 76 | let extrinsic = extrinsic.into_portable(&mut registry); 77 | let apis = registry.map_into_portable(apis); 78 | let outer_enums = outer_enums.into_portable(&mut registry); 79 | let custom = custom.into_portable(&mut registry); 80 | 81 | Self { 82 | types: registry.into(), 83 | pallets, 84 | extrinsic, 85 | apis, 86 | outer_enums, 87 | custom, 88 | } 89 | } 90 | } 91 | 92 | /// Metadata of a runtime trait. 93 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 94 | #[cfg_attr(feature = "decode", derive(Decode))] 95 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 96 | #[cfg_attr( 97 | feature = "serde_full", 98 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 99 | )] 100 | pub struct RuntimeApiMetadata { 101 | /// Trait name. 102 | pub name: T::String, 103 | /// Trait methods. 104 | pub methods: Vec>, 105 | /// Trait documentation. 106 | pub docs: Vec, 107 | /// Runtime API version. 108 | pub version: Compact, 109 | /// Deprecation info. 110 | pub deprecation_info: ItemDeprecationInfo, 111 | } 112 | 113 | impl IntoPortable for RuntimeApiMetadata { 114 | type Output = RuntimeApiMetadata; 115 | 116 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 117 | RuntimeApiMetadata { 118 | name: self.name.into_portable(registry), 119 | methods: registry.map_into_portable(self.methods), 120 | docs: registry.map_into_portable(self.docs), 121 | version: self.version, 122 | deprecation_info: self.deprecation_info.into_portable(registry), 123 | } 124 | } 125 | } 126 | 127 | /// Metadata of a runtime method. 128 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 129 | #[cfg_attr(feature = "decode", derive(Decode))] 130 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 131 | #[cfg_attr( 132 | feature = "serde_full", 133 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 134 | )] 135 | pub struct RuntimeApiMethodMetadata { 136 | /// Method name. 137 | pub name: T::String, 138 | /// Method parameters. 139 | pub inputs: Vec>, 140 | /// Method output. 141 | pub output: T::Type, 142 | /// Method documentation. 143 | pub docs: Vec, 144 | /// Deprecation info 145 | pub deprecation_info: ItemDeprecationInfo, 146 | } 147 | 148 | impl IntoPortable for RuntimeApiMethodMetadata { 149 | type Output = RuntimeApiMethodMetadata; 150 | 151 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 152 | RuntimeApiMethodMetadata { 153 | name: self.name.into_portable(registry), 154 | inputs: registry.map_into_portable(self.inputs), 155 | output: registry.register_type(&self.output), 156 | docs: registry.map_into_portable(self.docs), 157 | deprecation_info: self.deprecation_info.into_portable(registry), 158 | } 159 | } 160 | } 161 | 162 | /// Metadata of the extrinsic used by the runtime. 163 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 164 | #[cfg_attr(feature = "decode", derive(Decode))] 165 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 166 | #[cfg_attr( 167 | feature = "serde_full", 168 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 169 | )] 170 | pub struct ExtrinsicMetadata { 171 | /// Extrinsic versions supported by the runtime. 172 | pub versions: Vec, 173 | /// The type of the address that signs the extrinsic 174 | pub address_ty: T::Type, 175 | /// The type of the outermost Call enum. 176 | // Dev note: this is also exposed in outer_enums, but we duplicate 177 | // it here so that ExtrinsicMetadata, on its own, provides everything 178 | // needed to decode an extrinsic. 179 | pub call_ty: T::Type, 180 | /// The type of the extrinsic's signature. 181 | pub signature_ty: T::Type, 182 | /// A mapping of supported transaction extrinsic versions to their respective transaction extension indexes. 183 | /// 184 | /// For each supported version number, list the indexes, in order, of the extensions used. 185 | pub transaction_extensions_by_version: BTreeMap>>, 186 | /// The transaction extensions in the order they appear in the extrinsic. 187 | pub transaction_extensions: Vec>, 188 | } 189 | 190 | impl IntoPortable for ExtrinsicMetadata { 191 | type Output = ExtrinsicMetadata; 192 | 193 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 194 | ExtrinsicMetadata { 195 | versions: self.versions, 196 | address_ty: registry.register_type(&self.address_ty), 197 | call_ty: registry.register_type(&self.call_ty), 198 | signature_ty: registry.register_type(&self.signature_ty), 199 | transaction_extensions_by_version: self.transaction_extensions_by_version, 200 | transaction_extensions: registry.map_into_portable(self.transaction_extensions), 201 | } 202 | } 203 | } 204 | 205 | /// Metadata of an extrinsic's transaction extension. 206 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 207 | #[cfg_attr(feature = "decode", derive(Decode))] 208 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 209 | #[cfg_attr( 210 | feature = "serde_full", 211 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 212 | )] 213 | pub struct TransactionExtensionMetadata { 214 | /// The unique transaction extension identifier, which may be different from the type name. 215 | pub identifier: T::String, 216 | /// The type of the transaction extension, with the data to be included in the extrinsic. 217 | pub ty: T::Type, 218 | /// The type of the implicit data, with the data to be included in the signed payload. 219 | pub implicit: T::Type, 220 | } 221 | 222 | impl IntoPortable for TransactionExtensionMetadata { 223 | type Output = TransactionExtensionMetadata; 224 | 225 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 226 | TransactionExtensionMetadata { 227 | identifier: self.identifier.into_portable(registry), 228 | ty: registry.register_type(&self.ty), 229 | implicit: registry.register_type(&self.implicit), 230 | } 231 | } 232 | } 233 | 234 | /// All metadata about an runtime pallet. 235 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 236 | #[cfg_attr(feature = "decode", derive(Decode))] 237 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 238 | #[cfg_attr( 239 | feature = "serde_full", 240 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 241 | )] 242 | pub struct PalletMetadata { 243 | /// Pallet name. 244 | pub name: T::String, 245 | /// Pallet storage metadata. 246 | pub storage: Option>, 247 | /// Pallet calls metadata. 248 | pub calls: Option>, 249 | /// Pallet event metadata. 250 | pub event: Option>, 251 | /// Pallet constants metadata. 252 | pub constants: Vec>, 253 | /// Pallet error metadata. 254 | pub error: Option>, 255 | /// Config's trait associated types. 256 | pub associated_types: Vec>, 257 | /// Pallet view functions metadata. 258 | pub view_functions: Vec>, 259 | /// Define the index of the pallet, this index will be used for the encoding of pallet event, 260 | /// call and origin variants. 261 | pub index: u8, 262 | /// Pallet documentation. 263 | pub docs: Vec, 264 | /// Deprecation info 265 | pub deprecation_info: ItemDeprecationInfo, 266 | } 267 | 268 | impl IntoPortable for PalletMetadata { 269 | type Output = PalletMetadata; 270 | 271 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 272 | PalletMetadata { 273 | name: self.name.into_portable(registry), 274 | storage: self.storage.map(|storage| storage.into_portable(registry)), 275 | calls: self.calls.map(|calls| calls.into_portable(registry)), 276 | event: self.event.map(|event| event.into_portable(registry)), 277 | constants: registry.map_into_portable(self.constants), 278 | error: self.error.map(|error| error.into_portable(registry)), 279 | associated_types: registry.map_into_portable(self.associated_types), 280 | view_functions: registry.map_into_portable(self.view_functions), 281 | index: self.index, 282 | docs: registry.map_into_portable(self.docs), 283 | deprecation_info: self.deprecation_info.into_portable(registry), 284 | } 285 | } 286 | } 287 | 288 | /// Metadata for all calls in a pallet. 289 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 290 | #[cfg_attr(feature = "decode", derive(Decode))] 291 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 292 | #[cfg_attr( 293 | feature = "serde_full", 294 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 295 | )] 296 | pub struct PalletCallMetadata { 297 | /// The corresponding enum type for the pallet call. 298 | pub ty: T::Type, 299 | /// Deprecation status of the pallet call 300 | pub deprecation_info: EnumDeprecationInfo, 301 | } 302 | 303 | impl IntoPortable for PalletCallMetadata { 304 | type Output = PalletCallMetadata; 305 | 306 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 307 | PalletCallMetadata { 308 | ty: registry.register_type(&self.ty), 309 | deprecation_info: self.deprecation_info.into_portable(registry), 310 | } 311 | } 312 | } 313 | 314 | /// All metadata of the pallet's storage. 315 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 316 | #[cfg_attr(feature = "decode", derive(Decode))] 317 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 318 | #[cfg_attr( 319 | feature = "serde_full", 320 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 321 | )] 322 | pub struct PalletStorageMetadata { 323 | /// The common prefix used by all storage entries. 324 | pub prefix: T::String, 325 | /// Metadata for all storage entries. 326 | pub entries: Vec>, 327 | } 328 | 329 | impl IntoPortable for PalletStorageMetadata { 330 | type Output = PalletStorageMetadata; 331 | 332 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 333 | PalletStorageMetadata { 334 | prefix: self.prefix.into_portable(registry), 335 | entries: registry.map_into_portable(self.entries), 336 | } 337 | } 338 | } 339 | 340 | /// Metadata about one storage entry. 341 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 342 | #[cfg_attr(feature = "decode", derive(Decode))] 343 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 344 | #[cfg_attr( 345 | feature = "serde_full", 346 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 347 | )] 348 | pub struct StorageEntryMetadata { 349 | /// Variable name of the storage entry. 350 | pub name: T::String, 351 | /// An `Option` modifier of that storage entry. 352 | pub modifier: StorageEntryModifier, 353 | /// Type of the value stored in the entry. 354 | pub ty: StorageEntryType, 355 | /// Default value (SCALE encoded). 356 | pub default: Vec, 357 | /// Storage entry documentation. 358 | pub docs: Vec, 359 | /// Deprecation info 360 | pub deprecation_info: ItemDeprecationInfo, 361 | } 362 | 363 | impl IntoPortable for StorageEntryMetadata { 364 | type Output = StorageEntryMetadata; 365 | 366 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 367 | StorageEntryMetadata { 368 | name: self.name.into_portable(registry), 369 | modifier: self.modifier, 370 | ty: self.ty.into_portable(registry), 371 | default: self.default, 372 | docs: registry.map_into_portable(self.docs), 373 | deprecation_info: self.deprecation_info.into_portable(registry), 374 | } 375 | } 376 | } 377 | 378 | /// Metadata about the pallet Event type. 379 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 380 | #[cfg_attr(feature = "decode", derive(Decode))] 381 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 382 | #[cfg_attr( 383 | feature = "serde_full", 384 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 385 | )] 386 | pub struct PalletEventMetadata { 387 | /// The Event type. 388 | pub ty: T::Type, 389 | /// Deprecation info 390 | pub deprecation_info: EnumDeprecationInfo, 391 | } 392 | 393 | impl IntoPortable for PalletEventMetadata { 394 | type Output = PalletEventMetadata; 395 | 396 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 397 | PalletEventMetadata { 398 | ty: registry.register_type(&self.ty), 399 | deprecation_info: self.deprecation_info.into_portable(registry), 400 | } 401 | } 402 | } 403 | 404 | /// Metadata about one pallet constant. 405 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 406 | #[cfg_attr(feature = "decode", derive(Decode))] 407 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 408 | #[cfg_attr( 409 | feature = "serde_full", 410 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 411 | )] 412 | pub struct PalletConstantMetadata { 413 | /// Name of the pallet constant. 414 | pub name: T::String, 415 | /// Type of the pallet constant. 416 | pub ty: T::Type, 417 | /// Value stored in the constant (SCALE encoded). 418 | pub value: Vec, 419 | /// Documentation of the constant. 420 | pub docs: Vec, 421 | /// Deprecation info 422 | pub deprecation_info: ItemDeprecationInfo, 423 | } 424 | 425 | impl IntoPortable for PalletConstantMetadata { 426 | type Output = PalletConstantMetadata; 427 | 428 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 429 | PalletConstantMetadata { 430 | name: self.name.into_portable(registry), 431 | ty: registry.register_type(&self.ty), 432 | value: self.value, 433 | docs: registry.map_into_portable(self.docs), 434 | deprecation_info: self.deprecation_info.into_portable(registry), 435 | } 436 | } 437 | } 438 | 439 | /// Metadata about a pallet error. 440 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 441 | #[cfg_attr(feature = "decode", derive(Decode))] 442 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 443 | #[cfg_attr( 444 | feature = "serde_full", 445 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 446 | )] 447 | pub struct PalletErrorMetadata { 448 | /// The error type information. 449 | pub ty: T::Type, 450 | /// Deprecation info 451 | pub deprecation_info: EnumDeprecationInfo, 452 | } 453 | 454 | impl IntoPortable for PalletErrorMetadata { 455 | type Output = PalletErrorMetadata; 456 | 457 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 458 | PalletErrorMetadata { 459 | ty: registry.register_type(&self.ty), 460 | deprecation_info: self.deprecation_info.into_portable(registry), 461 | } 462 | } 463 | } 464 | 465 | /// Metadata of a pallet's associated type. 466 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 467 | #[cfg_attr(feature = "decode", derive(Decode))] 468 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 469 | #[cfg_attr( 470 | feature = "serde_full", 471 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 472 | )] 473 | pub struct PalletAssociatedTypeMetadata { 474 | /// The name of the associated type. 475 | pub name: T::String, 476 | /// The type of the associated type. 477 | pub ty: T::Type, 478 | /// The documentation of the associated type. 479 | pub docs: Vec, 480 | } 481 | 482 | impl IntoPortable for PalletAssociatedTypeMetadata { 483 | type Output = PalletAssociatedTypeMetadata; 484 | 485 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 486 | PalletAssociatedTypeMetadata { 487 | name: self.name.into_portable(registry), 488 | ty: registry.register_type(&self.ty), 489 | docs: registry.map_into_portable(self.docs), 490 | } 491 | } 492 | } 493 | 494 | /// Metadata about a pallet view function. 495 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 496 | #[cfg_attr(feature = "decode", derive(Decode))] 497 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 498 | #[cfg_attr( 499 | feature = "serde_full", 500 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 501 | )] 502 | pub struct PalletViewFunctionMetadata { 503 | /// Method id. 504 | pub id: [u8; 32], 505 | /// Method name. 506 | pub name: T::String, 507 | /// Method parameters. 508 | pub inputs: Vec>, 509 | /// Method output. 510 | pub output: T::Type, 511 | /// Method documentation. 512 | pub docs: Vec, 513 | /// Deprecation info 514 | pub deprecation_info: ItemDeprecationInfo, 515 | } 516 | 517 | impl IntoPortable for PalletViewFunctionMetadata { 518 | type Output = PalletViewFunctionMetadata; 519 | 520 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 521 | PalletViewFunctionMetadata { 522 | id: self.id, 523 | name: self.name.into_portable(registry), 524 | inputs: registry.map_into_portable(self.inputs), 525 | output: registry.register_type(&self.output), 526 | docs: registry.map_into_portable(self.docs), 527 | deprecation_info: self.deprecation_info.into_portable(registry), 528 | } 529 | } 530 | } 531 | 532 | /// Deprecation information for generic items. 533 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 534 | #[cfg_attr(feature = "decode", derive(Decode))] 535 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 536 | #[cfg_attr( 537 | feature = "serde_full", 538 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 539 | )] 540 | pub enum ItemDeprecationInfo { 541 | /// Item is not deprecated. 542 | NotDeprecated, 543 | /// Item is fully deprecated without a note. 544 | DeprecatedWithoutNote, 545 | /// Item is fully deprecated with a note and an optional `since` field. 546 | Deprecated { 547 | /// Note explaining the deprecation 548 | note: T::String, 549 | /// Optional value for noting the version when the deprecation occurred. 550 | since: Option, 551 | }, 552 | } 553 | 554 | impl IntoPortable for ItemDeprecationInfo { 555 | type Output = ItemDeprecationInfo; 556 | 557 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 558 | match self { 559 | Self::NotDeprecated => ItemDeprecationInfo::NotDeprecated, 560 | Self::DeprecatedWithoutNote => ItemDeprecationInfo::DeprecatedWithoutNote, 561 | Self::Deprecated { note, since } => { 562 | let note = note.into_portable(registry); 563 | let since = since.map(|x| x.into_portable(registry)); 564 | ItemDeprecationInfo::Deprecated { note, since } 565 | } 566 | } 567 | } 568 | } 569 | 570 | /// Deprecation information for enums in which specific variants can be deprecated. 571 | /// If the map is empty, then nothing is deprecated. 572 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 573 | #[cfg_attr(feature = "decode", derive(Decode))] 574 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 575 | #[cfg_attr( 576 | feature = "serde_full", 577 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 578 | )] 579 | pub struct EnumDeprecationInfo(pub BTreeMap>); 580 | 581 | impl EnumDeprecationInfo { 582 | /// Construct an instance in which nothing is marked for deprecation. 583 | pub fn nothing_deprecated() -> Self { 584 | Self(BTreeMap::new()) 585 | } 586 | 587 | /// Are any variants deprecated? 588 | pub fn has_deprecated_variants(&self) -> bool { 589 | !self.0.is_empty() 590 | } 591 | 592 | /// Is a specific variant deprecated? 593 | pub fn is_variant_deprecated(&self, variant_index: u8) -> bool { 594 | self.0.contains_key(&variant_index) 595 | } 596 | } 597 | 598 | impl IntoPortable for EnumDeprecationInfo { 599 | type Output = EnumDeprecationInfo; 600 | 601 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 602 | let entries = self 603 | .0 604 | .into_iter() 605 | .map(|(k, entry)| (k, entry.into_portable(registry))); 606 | EnumDeprecationInfo(entries.collect()) 607 | } 608 | } 609 | 610 | /// Deprecation information for an item or variant in the metadata. 611 | // Dev note: we use #[codec(index)] here to align the indexes with those 612 | // of ItemDeprecationInfo, allowing both can decode into this asa convenience. 613 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 614 | #[cfg_attr(feature = "decode", derive(Decode))] 615 | #[cfg_attr(feature = "serde_full", derive(Serialize))] 616 | #[cfg_attr( 617 | feature = "serde_full", 618 | serde(bound(serialize = "T::Type: Serialize, T::String: Serialize")) 619 | )] 620 | pub enum VariantDeprecationInfo { 621 | /// Variant is deprecated without a note. 622 | #[codec(index = 1)] 623 | DeprecatedWithoutNote, 624 | /// Variant is deprecated with a note and an optional `since` field. 625 | #[codec(index = 2)] 626 | Deprecated { 627 | /// Note explaining the deprecation 628 | note: T::String, 629 | /// Optional value for noting the version when the deprecation occurred. 630 | since: Option, 631 | }, 632 | } 633 | 634 | impl IntoPortable for VariantDeprecationInfo { 635 | type Output = VariantDeprecationInfo; 636 | 637 | fn into_portable(self, registry: &mut Registry) -> Self::Output { 638 | match self { 639 | Self::Deprecated { note, since } => { 640 | let note = note.into_portable(registry); 641 | let since = since.map(|x| x.into_portable(registry)); 642 | VariantDeprecationInfo::Deprecated { note, since } 643 | } 644 | Self::DeprecatedWithoutNote => VariantDeprecationInfo::DeprecatedWithoutNote, 645 | } 646 | } 647 | } 648 | -------------------------------------------------------------------------------- /frame-metadata/src/v8.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Metadata Version 8. Chains old enough to contain this metadata need a way to decode it. 17 | 18 | #![allow(missing_docs)] 19 | 20 | use crate::decode_different::*; 21 | use codec::{Encode, Output}; 22 | 23 | cfg_if::cfg_if! { 24 | if #[cfg(feature = "std")] { 25 | use codec::Decode; 26 | use serde::Serialize; 27 | 28 | type StringBuf = String; 29 | } else { 30 | extern crate alloc; 31 | use alloc::vec::Vec; 32 | 33 | /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. 34 | /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. 35 | type StringBuf = &'static str; 36 | } 37 | } 38 | 39 | /// Curent prefix of metadata 40 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 41 | 42 | /// All the metadata about a function. 43 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 44 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 45 | pub struct FunctionMetadata { 46 | /// Function name. 47 | pub name: DecodeDifferentStr, 48 | /// A list of arguments this function takes. 49 | pub arguments: DecodeDifferentArray, 50 | /// Function documentation. 51 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 52 | } 53 | 54 | /// All the metadata about a function argument. 55 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 56 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 57 | pub struct FunctionArgumentMetadata { 58 | /// Name of the variable for the argument. 59 | pub name: DecodeDifferentStr, 60 | /// Type of the parameter. 61 | pub ty: DecodeDifferentStr, 62 | } 63 | 64 | /// All the metadata about an outer event. 65 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 66 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 67 | pub struct OuterEventMetadata { 68 | /// Name of the event. 69 | pub name: DecodeDifferentStr, 70 | /// A list of event details. 71 | pub events: DecodeDifferentArray< 72 | (&'static str, FnEncode<&'static [EventMetadata]>), 73 | (StringBuf, Vec), 74 | >, 75 | } 76 | 77 | /// All the metadata about an event. 78 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 79 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 80 | pub struct EventMetadata { 81 | /// Name of the event. 82 | pub name: DecodeDifferentStr, 83 | /// Arguments of the event. 84 | pub arguments: DecodeDifferentArray<&'static str, StringBuf>, 85 | /// Documentation of the event. 86 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 87 | } 88 | 89 | /// All the metadata about one storage entry. 90 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 91 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 92 | pub struct StorageEntryMetadata { 93 | /// Variable name of the storage entry. 94 | pub name: DecodeDifferentStr, 95 | /// A storage modifier of the storage entry (is it optional? does it have a default value?). 96 | pub modifier: StorageEntryModifier, 97 | /// Type of the value stored in the entry. 98 | pub ty: StorageEntryType, 99 | /// Default value (SCALE encoded). 100 | pub default: ByteGetter, 101 | /// Storage entry documentation. 102 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 103 | } 104 | 105 | /// All the metadata about one module constant. 106 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 107 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 108 | pub struct ModuleConstantMetadata { 109 | /// Name of the module constant. 110 | pub name: DecodeDifferentStr, 111 | /// Type of the module constant. 112 | pub ty: DecodeDifferentStr, 113 | /// Value stored in the constant (SCALE encoded). 114 | pub value: ByteGetter, 115 | /// Documentation of the constant. 116 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 117 | } 118 | 119 | /// All the metadata about a module error. 120 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 121 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 122 | pub struct ErrorMetadata { 123 | /// Name of the error. 124 | pub name: DecodeDifferentStr, 125 | /// Error variant documentation. 126 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 127 | } 128 | 129 | /// All the metadata about errors in a module. 130 | pub trait ModuleErrorMetadata { 131 | /// Returns error metadata. 132 | fn metadata() -> &'static [ErrorMetadata]; 133 | } 134 | 135 | impl ModuleErrorMetadata for &'static str { 136 | fn metadata() -> &'static [ErrorMetadata] { 137 | &[] 138 | } 139 | } 140 | 141 | /// A technical trait to store lazy initiated vec value as static dyn pointer. 142 | pub trait DefaultByte: Send + Sync { 143 | /// A default value (SCALE encoded). 144 | fn default_byte(&self) -> Vec; 145 | } 146 | 147 | /// Wrapper over dyn pointer for accessing a cached once byte value. 148 | #[derive(Clone)] 149 | pub struct DefaultByteGetter(pub &'static dyn DefaultByte); 150 | 151 | /// Decode different for static lazy initiated byte value. 152 | pub type ByteGetter = DecodeDifferent>; 153 | 154 | impl Encode for DefaultByteGetter { 155 | fn encode_to(&self, dest: &mut W) { 156 | self.0.default_byte().encode_to(dest) 157 | } 158 | } 159 | 160 | impl codec::EncodeLike for DefaultByteGetter {} 161 | 162 | impl PartialEq for DefaultByteGetter { 163 | fn eq(&self, other: &DefaultByteGetter) -> bool { 164 | let left = self.0.default_byte(); 165 | let right = other.0.default_byte(); 166 | left.eq(&right) 167 | } 168 | } 169 | 170 | impl Eq for DefaultByteGetter {} 171 | 172 | #[cfg(feature = "std")] 173 | impl serde::Serialize for DefaultByteGetter { 174 | fn serialize(&self, serializer: S) -> Result 175 | where 176 | S: serde::Serializer, 177 | { 178 | self.0.default_byte().serialize(serializer) 179 | } 180 | } 181 | 182 | impl core::fmt::Debug for DefaultByteGetter { 183 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 184 | self.0.default_byte().fmt(f) 185 | } 186 | } 187 | 188 | /// Hasher used by storage maps 189 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 190 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 191 | pub enum StorageHasher { 192 | /// 128-bit Blake2 hash. 193 | Blake2_128, 194 | /// 256-bit Blake2 hash. 195 | Blake2_256, 196 | /// 128-bit XX hash. 197 | Twox128, 198 | /// 256-bit XX hash. 199 | Twox256, 200 | /// 64-bit XX hashes concatentation. 201 | Twox64Concat, 202 | } 203 | 204 | /// A storage entry type. 205 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 206 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 207 | pub enum StorageEntryType { 208 | /// Plain storage entry (just the value). 209 | Plain(DecodeDifferentStr), 210 | /// A storage map. 211 | Map { 212 | /// Hasher type for the keys. 213 | hasher: StorageHasher, 214 | /// Key type. 215 | key: DecodeDifferentStr, 216 | /// Value type. 217 | value: DecodeDifferentStr, 218 | is_linked: bool, 219 | }, 220 | /// Storage Double Map. 221 | DoubleMap { 222 | /// Hasher type for the keys. 223 | hasher: StorageHasher, 224 | /// First key type. 225 | key1: DecodeDifferentStr, 226 | /// Second key type. 227 | key2: DecodeDifferentStr, 228 | /// Value type. 229 | value: DecodeDifferentStr, 230 | /// Hasher for the second key. 231 | key2_hasher: StorageHasher, 232 | }, 233 | } 234 | 235 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 236 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 237 | /// 238 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 239 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 240 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 241 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 242 | pub enum StorageEntryModifier { 243 | /// The storage entry returns an `Option`, with `None` if the key is not present. 244 | Optional, 245 | /// The storage entry returns `T::Default` if the key is not present. 246 | Default, 247 | } 248 | 249 | /// All metadata of the storage. 250 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 251 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 252 | pub struct StorageMetadata { 253 | /// The common prefix used by all storage entries. 254 | pub prefix: DecodeDifferent<&'static str, StringBuf>, 255 | pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec>, 256 | } 257 | 258 | /// The metadata of a runtime. 259 | #[derive(Eq, Encode, PartialEq, Debug)] 260 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 261 | pub struct RuntimeMetadataV8 { 262 | pub modules: DecodeDifferentArray, 263 | } 264 | 265 | /// The latest version of the metadata. 266 | pub type RuntimeMetadataLastVersion = RuntimeMetadataV8; 267 | 268 | /// All metadata about a runtime module. 269 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 270 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 271 | pub struct ModuleMetadata { 272 | /// Module name. 273 | pub name: DecodeDifferentStr, 274 | pub storage: Option, StorageMetadata>>, 275 | pub calls: ODFnA, 276 | pub event: ODFnA, 277 | pub constants: DFnA, 278 | pub errors: DFnA, 279 | } 280 | 281 | type ODFnA = Option>; 282 | type DFnA = DecodeDifferent, Vec>; 283 | -------------------------------------------------------------------------------- /frame-metadata/src/v9.rs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Parity Technologies (UK) Ltd. 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | //! Metadata Version 9. Networks like/as old as Kusama start here. 17 | //! Chains old enough to contain this metadata need a way to decode it. 18 | 19 | #![allow(missing_docs)] 20 | 21 | use crate::decode_different::*; 22 | use codec::{Encode, Output}; 23 | 24 | cfg_if::cfg_if! { 25 | if #[cfg(feature = "std")] { 26 | use codec::Decode; 27 | use serde::Serialize; 28 | 29 | type StringBuf = String; 30 | } else { 31 | extern crate alloc; 32 | use alloc::vec::Vec; 33 | 34 | /// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`. 35 | /// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error. 36 | type StringBuf = &'static str; 37 | } 38 | } 39 | 40 | /// Curent prefix of metadata 41 | pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness 42 | 43 | /// All the metadata about a function. 44 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 45 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 46 | pub struct FunctionMetadata { 47 | pub name: DecodeDifferentStr, 48 | pub arguments: DecodeDifferentArray, 49 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 50 | } 51 | 52 | /// All the metadata about a function argument. 53 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 54 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 55 | pub struct FunctionArgumentMetadata { 56 | pub name: DecodeDifferentStr, 57 | pub ty: DecodeDifferentStr, 58 | } 59 | 60 | /// All the metadata about an outer event. 61 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 62 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 63 | pub struct OuterEventMetadata { 64 | pub name: DecodeDifferentStr, 65 | pub events: DecodeDifferentArray< 66 | (&'static str, FnEncode<&'static [EventMetadata]>), 67 | (StringBuf, Vec), 68 | >, 69 | } 70 | 71 | /// All the metadata about an event. 72 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 73 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 74 | pub struct EventMetadata { 75 | pub name: DecodeDifferentStr, 76 | pub arguments: DecodeDifferentArray<&'static str, StringBuf>, 77 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 78 | } 79 | 80 | /// All the metadata about one storage entry. 81 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 82 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 83 | pub struct StorageEntryMetadata { 84 | pub name: DecodeDifferentStr, 85 | pub modifier: StorageEntryModifier, 86 | pub ty: StorageEntryType, 87 | pub default: ByteGetter, 88 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 89 | } 90 | 91 | /// All the metadata about one module constant. 92 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 93 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 94 | pub struct ModuleConstantMetadata { 95 | pub name: DecodeDifferentStr, 96 | pub ty: DecodeDifferentStr, 97 | pub value: ByteGetter, 98 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 99 | } 100 | 101 | /// All the metadata about a module error. 102 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 103 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 104 | pub struct ErrorMetadata { 105 | pub name: DecodeDifferentStr, 106 | pub documentation: DecodeDifferentArray<&'static str, StringBuf>, 107 | } 108 | 109 | /// All the metadata about errors in a module. 110 | pub trait ModuleErrorMetadata { 111 | fn metadata() -> &'static [ErrorMetadata]; 112 | } 113 | 114 | impl ModuleErrorMetadata for &'static str { 115 | fn metadata() -> &'static [ErrorMetadata] { 116 | &[] 117 | } 118 | } 119 | 120 | /// A technical trait to store lazy initiated vec value as static dyn pointer. 121 | pub trait DefaultByte: Send + Sync { 122 | fn default_byte(&self) -> Vec; 123 | } 124 | 125 | /// Wrapper over dyn pointer for accessing a cached once byte value. 126 | #[derive(Clone)] 127 | pub struct DefaultByteGetter(pub &'static dyn DefaultByte); 128 | 129 | /// Decode different for static lazy initiated byte value. 130 | pub type ByteGetter = DecodeDifferent>; 131 | 132 | impl Encode for DefaultByteGetter { 133 | fn encode_to(&self, dest: &mut W) { 134 | self.0.default_byte().encode_to(dest) 135 | } 136 | } 137 | 138 | impl codec::EncodeLike for DefaultByteGetter {} 139 | 140 | impl PartialEq for DefaultByteGetter { 141 | fn eq(&self, other: &DefaultByteGetter) -> bool { 142 | let left = self.0.default_byte(); 143 | let right = other.0.default_byte(); 144 | left.eq(&right) 145 | } 146 | } 147 | 148 | impl Eq for DefaultByteGetter {} 149 | 150 | #[cfg(feature = "std")] 151 | impl serde::Serialize for DefaultByteGetter { 152 | fn serialize(&self, serializer: S) -> Result 153 | where 154 | S: serde::Serializer, 155 | { 156 | self.0.default_byte().serialize(serializer) 157 | } 158 | } 159 | 160 | impl core::fmt::Debug for DefaultByteGetter { 161 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 162 | self.0.default_byte().fmt(f) 163 | } 164 | } 165 | 166 | /// Hasher used by storage maps 167 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 168 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 169 | pub enum StorageHasher { 170 | Blake2_128, 171 | Blake2_256, 172 | Blake2_128Concat, 173 | Twox128, 174 | Twox256, 175 | Twox64Concat, 176 | } 177 | 178 | /// A storage entry type. 179 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 180 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 181 | pub enum StorageEntryType { 182 | Plain(DecodeDifferentStr), 183 | Map { 184 | hasher: StorageHasher, 185 | key: DecodeDifferentStr, 186 | value: DecodeDifferentStr, 187 | is_linked: bool, 188 | }, 189 | DoubleMap { 190 | hasher: StorageHasher, 191 | key1: DecodeDifferentStr, 192 | key2: DecodeDifferentStr, 193 | value: DecodeDifferentStr, 194 | key2_hasher: StorageHasher, 195 | }, 196 | } 197 | 198 | /// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present. 199 | /// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present. 200 | /// 201 | /// `Optional` means you should expect an `Option`, with `None` returned if the key is not present. 202 | /// `Default` means you should expect a `T` with the default value of default if the key is not present. 203 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 204 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 205 | pub enum StorageEntryModifier { 206 | Optional, 207 | Default, 208 | } 209 | 210 | /// All metadata of the storage. 211 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 212 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 213 | pub struct StorageMetadata { 214 | /// The common prefix used by all storage entries. 215 | pub prefix: DecodeDifferent<&'static str, StringBuf>, 216 | pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec>, 217 | } 218 | 219 | /// The metadata of a runtime. 220 | #[derive(Eq, Encode, PartialEq, Debug)] 221 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 222 | pub struct RuntimeMetadataV9 { 223 | pub modules: DecodeDifferentArray, 224 | } 225 | 226 | /// All metadata about an runtime module. 227 | #[derive(Clone, PartialEq, Eq, Encode, Debug)] 228 | #[cfg_attr(feature = "std", derive(Decode, Serialize))] 229 | pub struct ModuleMetadata { 230 | pub name: DecodeDifferentStr, 231 | pub storage: Option, StorageMetadata>>, 232 | pub calls: ODFnA, 233 | pub event: ODFnA, 234 | pub constants: DFnA, 235 | pub errors: DFnA, 236 | } 237 | 238 | type ODFnA = Option>; 239 | type DFnA = DecodeDifferent, Vec>; 240 | -------------------------------------------------------------------------------- /frame-metadata/test_data/ksm_metadata_v10.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paritytech/frame-metadata/f0742f8449233421d4db60e22175e26abaf68762/frame-metadata/test_data/ksm_metadata_v10.bin -------------------------------------------------------------------------------- /frame-metadata/test_data/ksm_metadata_v11.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paritytech/frame-metadata/f0742f8449233421d4db60e22175e26abaf68762/frame-metadata/test_data/ksm_metadata_v11.bin -------------------------------------------------------------------------------- /frame-metadata/test_data/ksm_metadata_v12.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paritytech/frame-metadata/f0742f8449233421d4db60e22175e26abaf68762/frame-metadata/test_data/ksm_metadata_v12.bin -------------------------------------------------------------------------------- /frame-metadata/test_data/ksm_metadata_v13.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paritytech/frame-metadata/f0742f8449233421d4db60e22175e26abaf68762/frame-metadata/test_data/ksm_metadata_v13.bin -------------------------------------------------------------------------------- /frame-metadata/test_data/ksm_metadata_v14.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paritytech/frame-metadata/f0742f8449233421d4db60e22175e26abaf68762/frame-metadata/test_data/ksm_metadata_v14.bin -------------------------------------------------------------------------------- /frame-metadata/test_data/ksm_metadata_v9.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paritytech/frame-metadata/f0742f8449233421d4db60e22175e26abaf68762/frame-metadata/test_data/ksm_metadata_v9.bin -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | hard_tabs = true 2 | --------------------------------------------------------------------------------