From 9015a0fcea375291162f62e4da3a3eb0d60fbadf Mon Sep 17 00:00:00 2001
From: Giuseppe Re <giuseppe.re@parity.io>
Date: Mon, 17 Feb 2025 12:18:56 +0100
Subject: [PATCH] Bump frame-metadata v16 to 19.0.0 (#7563)

Update to latest version of `frame-metadata` in order to support pallet
view function metadata.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
---
 Cargo.lock                                    | 22 ++++++-------
 Cargo.toml                                    |  4 +--
 prdoc/pr_7563.prdoc                           | 14 ++++++++
 .../primitives/metadata-ir/src/unstable.rs    | 32 +++++++++++++++----
 4 files changed, 53 insertions(+), 19 deletions(-)
 create mode 100644 prdoc/pr_7563.prdoc

diff --git a/Cargo.lock b/Cargo.lock
index 4fad3c33112..40594efe42d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7424,9 +7424,9 @@ dependencies = [
 
 [[package]]
 name = "frame-metadata"
-version = "18.0.0"
+version = "19.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "daaf440c68eb2c3d88e5760fe8c7af3f9fee9181fab6c2f2c4e7cc48dcc40bb8"
+checksum = "835a2e736d544b98dab966b4b9541f15af416288a86c3738fdd67bd9fbc4696e"
 dependencies = [
  "cfg-if",
  "parity-scale-codec",
@@ -7441,7 +7441,7 @@ dependencies = [
  "array-bytes",
  "const-hex",
  "docify",
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "frame-support 28.0.0",
  "frame-system 28.0.0",
  "log",
@@ -7526,7 +7526,7 @@ dependencies = [
  "bitflags 1.3.2",
  "docify",
  "environmental",
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "frame-support-procedural 23.0.0",
  "frame-system 28.0.0",
  "impl-trait-for-tuples",
@@ -7704,7 +7704,7 @@ version = "3.0.0"
 dependencies = [
  "frame-benchmarking 28.0.0",
  "frame-executive 28.0.0",
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "frame-support 28.0.0",
  "frame-support-test-pallet",
  "frame-system 28.0.0",
@@ -10771,13 +10771,13 @@ dependencies = [
 
 [[package]]
 name = "merkleized-metadata"
-version = "0.2.0"
+version = "0.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38c592efaf1b3250df14c8f3c2d952233f0302bb81d3586db2f303666c1cd607"
+checksum = "e656ca4a152e892cbbf4b621c242b070136643b797709007d4861881d71ff4c9"
 dependencies = [
  "array-bytes",
  "blake3",
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "parity-scale-codec",
  "scale-decode 0.13.1",
  "scale-info",
@@ -13668,7 +13668,7 @@ name = "pallet-example-view-functions"
 version = "1.0.0"
 dependencies = [
  "frame-benchmarking 28.0.0",
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "frame-support 28.0.0",
  "frame-system 28.0.0",
  "log",
@@ -26969,7 +26969,7 @@ dependencies = [
 name = "sp-metadata-ir"
 version = "0.6.0"
 dependencies = [
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "parity-scale-codec",
  "scale-info",
 ]
@@ -29074,7 +29074,7 @@ dependencies = [
  "cargo_metadata",
  "console",
  "filetime",
- "frame-metadata 18.0.0",
+ "frame-metadata 19.0.0",
  "jobserver",
  "merkleized-metadata",
  "parity-scale-codec",
diff --git a/Cargo.toml b/Cargo.toml
index 1e7bec5e831..987e57d418b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -785,7 +785,7 @@ frame-benchmarking-pallet-pov = { default-features = false, path = "substrate/fr
 frame-election-provider-solution-type = { path = "substrate/frame/election-provider-support/solution-type", default-features = false }
 frame-election-provider-support = { path = "substrate/frame/election-provider-support", default-features = false }
 frame-executive = { path = "substrate/frame/executive", default-features = false }
-frame-metadata = { version = "18.0.0", default-features = false }
+frame-metadata = { version = "19.0.0", default-features = false }
 frame-metadata-hash-extension = { path = "substrate/frame/metadata-hash-extension", default-features = false }
 frame-support = { path = "substrate/frame/support", default-features = false }
 frame-support-procedural = { path = "substrate/frame/support/procedural", default-features = false }
@@ -860,7 +860,7 @@ macro_magic = { version = "0.5.1" }
 maplit = { version = "1.0.2" }
 memmap2 = { version = "0.9.3" }
 memory-db = { version = "0.32.0", default-features = false }
-merkleized-metadata = { version = "0.2.0" }
+merkleized-metadata = { version = "0.3.0" }
 merlin = { version = "3.0", default-features = false }
 messages-relay = { path = "bridges/relays/messages" }
 metered = { version = "0.6.1", default-features = false, package = "prioritized-metered-channel" }
diff --git a/prdoc/pr_7563.prdoc b/prdoc/pr_7563.prdoc
new file mode 100644
index 00000000000..a24e4a3d83b
--- /dev/null
+++ b/prdoc/pr_7563.prdoc
@@ -0,0 +1,14 @@
+title: Bump frame-metadata v16 to 19.0.0
+doc:
+- audience: Runtime Dev
+  description: Update to latest version of `frame-metadata` and `merkleized-metadata` in order to support pallet
+    view function metadata.
+crates:
+- name: sp-metadata-ir
+  bump: minor
+- name: frame-support
+  bump: none
+- name: substrate-wasm-builder
+  bump: minor
+- name: pallet-example-view-functions
+  bump: minor
diff --git a/substrate/primitives/metadata-ir/src/unstable.rs b/substrate/primitives/metadata-ir/src/unstable.rs
index 412cb78ce84..d03a7ddad26 100644
--- a/substrate/primitives/metadata-ir/src/unstable.rs
+++ b/substrate/primitives/metadata-ir/src/unstable.rs
@@ -20,7 +20,8 @@
 use crate::{
 	DeprecationInfoIR, DeprecationStatusIR, OuterEnumsIR, PalletAssociatedTypeMetadataIR,
 	PalletCallMetadataIR, PalletConstantMetadataIR, PalletErrorMetadataIR, PalletEventMetadataIR,
-	PalletStorageMetadataIR, StorageEntryMetadataIR,
+	PalletStorageMetadataIR, PalletViewFunctionMethodMetadataIR,
+	PalletViewFunctionMethodParamMetadataIR, StorageEntryMetadataIR,
 };
 
 use super::types::{
@@ -31,9 +32,10 @@ use super::types::{
 use frame_metadata::v16::{
 	CustomMetadata, DeprecationInfo, DeprecationStatus, ExtrinsicMetadata, OuterEnums,
 	PalletAssociatedTypeMetadata, PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata,
-	PalletEventMetadata, PalletMetadata, PalletStorageMetadata, RuntimeApiMetadata,
-	RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV16,
-	StorageEntryMetadata, TransactionExtensionMetadata,
+	PalletEventMetadata, PalletMetadata, PalletStorageMetadata, PalletViewFunctionMetadata,
+	PalletViewFunctionParamMetadata, RuntimeApiMetadata, RuntimeApiMethodMetadata,
+	RuntimeApiMethodParamMetadata, RuntimeMetadataV16, StorageEntryMetadata,
+	TransactionExtensionMetadata,
 };
 
 impl From<MetadataIR> for RuntimeMetadataV16 {
@@ -85,8 +87,7 @@ impl From<PalletMetadataIR> for PalletMetadata {
 			name: ir.name,
 			storage: ir.storage.map(Into::into),
 			calls: ir.calls.map(Into::into),
-			// TODO: add with the new v16 release of frame-metadata
-			// view_functions: ir.view_functions.into_iter().map(Into::into).collect(),
+			view_functions: ir.view_functions.into_iter().map(Into::into).collect(),
 			event: ir.event.map(Into::into),
 			constants: ir.constants.into_iter().map(Into::into).collect(),
 			error: ir.error.map(Into::into),
@@ -144,6 +145,25 @@ impl From<PalletCallMetadataIR> for PalletCallMetadata {
 	}
 }
 
+impl From<PalletViewFunctionMethodMetadataIR> for PalletViewFunctionMetadata {
+	fn from(ir: PalletViewFunctionMethodMetadataIR) -> Self {
+		PalletViewFunctionMetadata {
+			name: ir.name,
+			id: ir.id,
+			inputs: ir.inputs.into_iter().map(Into::into).collect(),
+			output: ir.output,
+			docs: ir.docs.into_iter().map(Into::into).collect(),
+			deprecation_info: ir.deprecation_info.into(),
+		}
+	}
+}
+
+impl From<PalletViewFunctionMethodParamMetadataIR> for PalletViewFunctionParamMetadata {
+	fn from(ir: PalletViewFunctionMethodParamMetadataIR) -> Self {
+		PalletViewFunctionParamMetadata { name: ir.name, ty: ir.ty }
+	}
+}
+
 impl From<PalletConstantMetadataIR> for PalletConstantMetadata {
 	fn from(ir: PalletConstantMetadataIR) -> Self {
 		PalletConstantMetadata {
-- 
GitLab