From a62f3f824cfef70db61816d513cae0102abf86aa Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 11 Mar 2021 13:09:58 -0500 Subject: [PATCH 1/2] Add a memo field --- runtime/common/src/crowdloan.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/crowdloan.rs b/runtime/common/src/crowdloan.rs index b68c51aa67c2..a7a73ee4540b 100644 --- a/runtime/common/src/crowdloan.rs +++ b/runtime/common/src/crowdloan.rs @@ -322,7 +322,8 @@ decl_module! { origin, #[compact] index: FundIndex, #[compact] value: BalanceOf, - signature: Option + signature: Option, + _memo: [u8; 32], ) { let who = ensure_signed(origin)?; From 14bdf801d149a74a6cff94d79e5da2d822e1b7fe Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Mon, 15 Mar 2021 15:56:43 -0400 Subject: [PATCH 2/2] switch to Vec --- runtime/common/src/crowdloan.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/crowdloan.rs b/runtime/common/src/crowdloan.rs index cc95cc88d4bd..317f60513fff 100644 --- a/runtime/common/src/crowdloan.rs +++ b/runtime/common/src/crowdloan.rs @@ -112,6 +112,9 @@ impl WeightInfo for TestWeightInfo { fn on_initialize(_n: u32, ) -> Weight { 0 } } +/// Maximum byte length of the memo attached to a contribution. +const MAX_MEMO_LENGTH: usize = 64; + pub trait Config: frame_system::Config { type Event: From> + Into<::Event>; @@ -283,6 +286,8 @@ decl_error! { NotReadyToDissolve, /// Invalid signature. InvalidSignature, + /// The memo attached to this contribution is too long. + MemoTooLong, } } @@ -354,11 +359,12 @@ decl_module! { #[compact] index: ParaId, #[compact] value: BalanceOf, signature: Option, - _memo: [u8; 32], + memo: Vec, ) { let who = ensure_signed(origin)?; ensure!(value >= T::MinContribution::get(), Error::::ContributionTooSmall); + ensure!(memo.len() < MAX_MEMO_LENGTH, Error::::MemoTooLong); let mut fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; fund.raised = fund.raised.checked_add(&value).ok_or(Error::::Overflow)?; ensure!(fund.raised <= fund.cap, Error::::CapExceeded);