From 91228dbd8116c64709888da903fcd1c06b839883 Mon Sep 17 00:00:00 2001 From: cdamian <17934949+cdamian@users.noreply.github.com> Date: Tue, 26 Dec 2023 15:59:14 +0100 Subject: [PATCH] remarks: Add remarks pallet --- Cargo.lock | 15 +++++++++++++ Cargo.toml | 3 ++- runtime/common/src/lib.rs | 1 + runtime/common/src/remarks.rs | 39 ++++++++++++++++++++++++++++++++++ runtime/development/Cargo.toml | 4 ++++ runtime/development/src/lib.rs | 18 +++++++++++++++- 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 runtime/common/src/remarks.rs diff --git a/Cargo.lock b/Cargo.lock index 90956be429..74e6604121 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2812,6 +2812,7 @@ dependencies = [ "pallet-pool-system", "pallet-preimage", "pallet-proxy", + "pallet-remarks", "pallet-restricted-tokens", "pallet-restricted-xtokens", "pallet-rewards", @@ -8425,6 +8426,20 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-remarks" +version = "0.0.1" +source = "git+https://github.com/foss3/runtime-pallet-library?branch=polkadot-v0.9.43#4c6aa68ce21729b835e56b8aaf1b76040a4cf189" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec 3.6.5", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-restricted-tokens" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fc6eb1b9e9..9a1f31776c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -243,6 +243,7 @@ chainbridge = { git = "https://github.com/centrifuge/chainbridge-substrate.git", # Foss3 mock-builder = { git = "https://github.com/foss3/runtime-pallet-library", branch = "polkadot-v0.9.43" } +pallet-remarks = { git = "https://github.com/foss3/runtime-pallet-library", branch = "polkadot-v0.9.43", default-features = false } # Centrifuge pallets axelar-gateway-precompile = { path = "pallets/liquidity-pools-gateway/axelar-gateway-precompile", default-features = false } @@ -285,7 +286,7 @@ cfg-types = { path = "libs/types", default-features = false } cfg-utils = { path = "libs/utils", default-features = false } cfg-mocks = { path = "libs/mocks", default-features = false } -# Centrifuge uuntimes +# Centrifuge runtimes runtime-common = { path = "runtime/common", default-features = false } development-runtime = { path = "runtime/development", default-features = false } altair-runtime = { path = "runtime/altair", default-features = false } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 51e6d84b87..7715d1567c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,6 +23,7 @@ pub mod fees; pub mod gateway; pub mod migrations; pub mod oracle; +pub mod remarks; pub mod transfer_filter; pub mod xcm; diff --git a/runtime/common/src/remarks.rs b/runtime/common/src/remarks.rs new file mode 100644 index 0000000000..1a8a6f5cd7 --- /dev/null +++ b/runtime/common/src/remarks.rs @@ -0,0 +1,39 @@ +// Copyright 2023 Centrifuge Foundation (centrifuge.io). +// +// This file is part of the Centrifuge chain project. +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use cfg_primitives::LoanId; +use frame_support::{dispatch::TypeInfo, parameter_types, BoundedVec}; +use sp_runtime::codec::{Decode, Encode}; +use sp_std::vec; + +parameter_types! { + pub const IpfsHashLength: u32 = 64; + pub const MaxNamedRemark: u32 = 1024; +} + +#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo)] +pub enum Remark { + /// IPFS hash + IpfsHash(BoundedVec), + + /// UTF-8 encoded string + Named(BoundedVec), + + /// Association with a loan + Loan(LoanId), +} + +impl Default for Remark { + fn default() -> Self { + Remark::Named(BoundedVec::try_from(vec![]).unwrap()) + } +} diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 4e230ebeac..aed868e6e7 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -122,6 +122,7 @@ pallet-pool-registry = { workspace = true } pallet-pool-system = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } +pallet-remarks = { workspace = true } pallet-restricted-tokens = { workspace = true } pallet-restricted-xtokens = { workspace = true } pallet-rewards = { workspace = true } @@ -250,6 +251,7 @@ std = [ "pallet-pool-system/std", "pallet-preimage/std", "pallet-proxy/std", + "pallet-remarks/std", "pallet-restricted-tokens/std", "pallet-restricted-xtokens/std", "pallet-rewards/std", @@ -338,6 +340,7 @@ runtime-benchmarks = [ "pallet-pool-system/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-remarks/runtime-benchmarks", "pallet-restricted-tokens/runtime-benchmarks", "pallet-restricted-xtokens/runtime-benchmarks", "pallet-rewards/runtime-benchmarks", @@ -426,6 +429,7 @@ try-runtime = [ "pallet-pool-system/try-runtime", "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", + "pallet-remarks/try-runtime", "pallet-restricted-tokens/try-runtime", "pallet-restricted-xtokens/try-runtime", "pallet-rewards/try-runtime", diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index b0eb967ff2..8d5bc9c7fb 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1819,6 +1819,19 @@ impl pallet_order_book::Config for Runtime { type Weights = weights::pallet_order_book::WeightInfo; } +parameter_types! { + pub const MaxRemarksPerCall: u32 = 10; +} + +impl pallet_remarks::Config for Runtime { + type MaxRemarksPerCall = MaxRemarksPerCall; + type Remark = Remark; + type RemarkDispatchHandler = pallet_remarks::NoopRemarkDispatchHandler; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + // Frame Order in this block dictates the index of each one in the metadata // Any addition should be done at the bottom // Any deletion affects the following frames during runtime upgrades @@ -1890,6 +1903,7 @@ construct_runtime!( ForeignInvestments: pallet_foreign_investments::{Pallet, Storage, Event} = 117, OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event} = 118, OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event} = 119, + Remarks: pallet_remarks::{Pallet, Call, Event} = 130, // XCM XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, @@ -2076,7 +2090,7 @@ mod __runtime_api_use { #[cfg(not(feature = "disable-runtime-api"))] use __runtime_api_use::*; -use runtime_common::transfer_filter::PreNativeTransfer; +use runtime_common::{remarks::Remark, transfer_filter::PreNativeTransfer}; #[cfg(not(feature = "disable-runtime-api"))] impl_runtime_apis! { @@ -2608,6 +2622,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_xcm, PolkadotXcm); add_benchmark!(params, batches, pallet_oracle_feed, OraclePriceFeed); add_benchmark!(params, batches, pallet_oracle_collection, OraclePriceCollection); + add_benchmark!(params, batches, pallet_remarks, Remarks); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) @@ -2667,6 +2682,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_xcm, PolkadotXcm); list_benchmark!(list, extra, pallet_oracle_feed, OraclePriceFeed); list_benchmark!(list, extra, pallet_oracle_collection, OraclePriceCollection); + list_benchmark!(list, extra, pallet_remarks, Remarks); let storage_info = AllPalletsWithSystem::storage_info();