크라우드펀딩 구성하기
FRAME 팔렛을 사용하여 크라우드펀딩 캠페인을 만드는 방법을 알려드립니다.
시작하기 전에
use frame_support::{
ensure,
pallet_prelude::*,
sp_runtime::traits::{AccountIdConversion, Hash, Saturating, Zero},
storage::child,
traits::{Currency, ExistenceRequirement, Get, ReservableCurrency, WithdrawReasons},
PalletId,
};
use frame_system::{pallet_prelude::*, ensure_signed};
use super::*;팔렛 구성하기
/// 팔렛의 구성 특성. #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; type Currency: ReservableCurrency<Self::AccountId>; type SubmissionDeposit: Get<BalanceOf<Self>>; type MinContribution: Get<BalanceOf<Self>>; type RetirementPeriod: Get<Self::BlockNumber>; }pub type FundIndex = u32; type AccountIdOf<T> = <T as frame_system::Config>::AccountId; type BalanceOf<T> = <<T as Config>::Currency as Currency<AccountIdOf<T>>>::Balance;#[derive(Encode, Decode, Default, PartialEq, Eq, TypeInfo)] #[cfg_attr(feature = "std", derive(Debug))] pub struct FundInfo<AccountId, Balance, BlockNumber> { /// 캠페인이 성공하면 자금을 받을 계정입니다. beneficiary: AccountId, /// 예치금액입니다. deposit: Balance, /// 모금된 총 금액입니다. raised: Balance, /// 자금 조달이 성공해야 하는 블록 번호입니다. end: BlockNumber, /// `raised`의 상한입니다. goal: Balance, }type FundInfoOf<T> = FundInfo<AccountIdOf<T>, BalanceOf<T>, <T as frame_system::Config>::BlockNumber>;#[pallet::storage] #[pallet::getter(fn funds)] /// 모든 펀드에 대한 정보입니다. pub(super) type Funds<T: Config> = StorageMap< _, Blake2_128Concat, FundIndex, FundInfoOf<T>, OptionQuery, >; #[pallet::storage] #[pallet::getter(fn fund_count)] /// 지금까지 할당된 펀드의 총 수입니다. pub(super) type FundCount<T: Config> = StorageValue<_, FundIndex, ValueQuery>;
자식 트라이(Trie) API 도우미 함수 작성하기
디스패처 함수 작성하기
예제
자원
Last updated