Skip to content

Commit

Permalink
remarks: Add remarks pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Jan 3, 2024
1 parent 3f0ca0c commit 91228db
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 39 additions & 0 deletions runtime/common/src/remarks.rs
Original file line number Diff line number Diff line change
@@ -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<u8, IpfsHashLength>),

/// UTF-8 encoded string
Named(BoundedVec<u8, MaxNamedRemark>),

/// Association with a loan
Loan(LoanId),
}

impl Default for Remark {
fn default() -> Self {
Remark::Named(BoundedVec::try_from(vec![]).unwrap())
}
}
4 changes: 4 additions & 0 deletions runtime/development/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 17 additions & 1 deletion runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,19 @@ impl pallet_order_book::Config for Runtime {
type Weights = weights::pallet_order_book::WeightInfo<Runtime>;
}

parameter_types! {
pub const MaxRemarksPerCall: u32 = 10;
}

impl pallet_remarks::Config for Runtime {
type MaxRemarksPerCall = MaxRemarksPerCall;
type Remark = Remark;
type RemarkDispatchHandler = pallet_remarks::NoopRemarkDispatchHandler<Runtime>;
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
Expand Down Expand Up @@ -1890,6 +1903,7 @@ construct_runtime!(
ForeignInvestments: pallet_foreign_investments::{Pallet, Storage, Event<T>} = 117,
OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event<T>} = 118,
OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event<T>} = 119,
Remarks: pallet_remarks::{Pallet, Call, Event<T>} = 130,

// XCM
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 120,
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 91228db

Please sign in to comment.