Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a memo field to crowdloan::contribute #2613

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion runtime/common/src/crowdloan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event<Self>> + Into<<Self as frame_system::Config>::Event>;

Expand Down Expand Up @@ -283,6 +286,8 @@ decl_error! {
NotReadyToDissolve,
/// Invalid signature.
InvalidSignature,
/// The memo attached to this contribution is too long.
MemoTooLong,
}
}

Expand Down Expand Up @@ -353,11 +358,13 @@ decl_module! {
pub fn contribute(origin,
#[compact] index: ParaId,
#[compact] value: BalanceOf<T>,
signature: Option<MultiSignature>
signature: Option<MultiSignature>,
memo: Vec<u8>,
) {
let who = ensure_signed(origin)?;

ensure!(value >= T::MinContribution::get(), Error::<T>::ContributionTooSmall);
ensure!(memo.len() < MAX_MEMO_LENGTH, Error::<T>::MemoTooLong);
let mut fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
fund.raised = fund.raised.checked_add(&value).ok_or(Error::<T>::Overflow)?;
ensure!(fund.raised <= fund.cap, Error::<T>::CapExceeded);
Expand Down