democracy模塊(全民公投)
說明
- 這個模塊用于公眾投票原献, 凡是substrate中有ensure_root權(quán)限要求的, 都可以通過這個模塊來執(zhí)行展东。
- 發(fā)起提案 -> 附議 -> 每個周期去查看柜思, 哪個附儀最多 -> 進入公投階段
- 只有進入
Preimages
的提案才能執(zhí)行 - 不能同時是驗證人和提名人
存儲
-
PublicProps
目前的公投 -
ReferendumInfoOf
公投的信息
常量
-
MinimumDeposit
提案需要的最小抵押金額
數(shù)據(jù)結(jié)構(gòu)
/// 投票的參數(shù)
pub enum AccountVote<Balance> {
/// A standard vote, one-way (approve or reject) with a given amount of conviction.
/// 只選一方來投
Standard { vote: Vote, balance: Balance },
/// A split vote with balances given for both ways, and with no conviction, useful for
/// parachains when voting.
/// 兩邊都投
Split { aye: Balance, nay: Balance },
}
pub struct Vote {
pub aye: bool,
pub conviction: Conviction,
}
/// 公投狀態(tài)
pub struct ReferendumStatus<BlockNumber, Hash, Balance> {
/// When voting on this referendum will end.
pub(crate) end: BlockNumber,
/// The hash of the proposal being voted on.
pub(crate) proposal_hash: Hash,
/// The thresholding mechanism to determine whether it passed.
pub(crate) threshold: VoteThreshold,
/// The delay (in blocks) to wait after a successful referendum before deploying.
pub(crate) delay: BlockNumber,
/// The current tally of votes in this referendum.
/// 這次全民公決目前的計票結(jié)果
pub(crate) tally: Tally<Balance>,
}
/// A means of determining if a vote is past pass threshold.
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, sp_runtime::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum VoteThreshold {
/// A supermajority of approvals is needed to pass this vote.
SuperMajorityApprove,
/// A supermajority of rejects is needed to fail this vote.
SuperMajorityAgainst,
/// A simple majority of approvals is needed to pass this vote.
SimpleMajority,
}
重要方法(對外接口)
-
提公投提案
- 代碼 `pub fn propose(
origin: OriginFor<T>,
proposal_hash: T::Hash,[pallet::compact] value: BalanceOf<T>,
)` - 參數(shù)
-
proposal_hash
提按hash -
value
愿意為這個提案抵押的金額
-
- 邏輯
-
value
要大于最小要求金額 - 目前的公投列表長度有限制
- 這個提案的hash如果在黑名單中岩调, 那么必須要到期才能重新提
問題 為什么沒有重復(fù)提案的查詢???
*** -
- 代碼 `pub fn propose(
-
附議
- 代碼 `pub fn second(
origin: OriginFor<T>,[pallet::compact] proposal: PropIndex,
[pallet::compact] seconds_upper_bound: u32,
)` - 參數(shù)
-
proposal
提案索引 -
seconds_upper_bound
(沒啥卵用的東西 盡量設(shè)置大一點)
-
- 邏輯
- 抵押跟提按發(fā)起人相同的金額(更新相關(guān)存儲
DepositOf
)
- 抵押跟提按發(fā)起人相同的金額(更新相關(guān)存儲
- 代碼 `pub fn second(
-
對提案進行公投
- 代碼 `pub fn vote(
origin: OriginFor<T>,[pallet::compact] ref_index: ReferendumIndex,
vote: AccountVote<BalanceOf<T>>,
)` - 參數(shù)
-
ref_index
公投索引 -
vote
投票方式(贊成與反對, 投票金額)
-
- 邏輯
- 投票金額一定要小于等于自己的自由余額
- 不能是已經(jīng)委托的
- 鎖倉投票金額
- 代碼 `pub fn vote(
-
緊急取消公投
- 代碼 `pub fn cancel_referendum(
origin: OriginFor<T>,[pallet::compact] ref_index: ReferendumIndex,
)` - 參數(shù)
-
ref_index
公投索引
-
- 邏輯
- 至少2/3議會權(quán)限
- 不能重復(fù)操作
- 刪除公投
- 代碼 `pub fn cancel_referendum(
-
todo
- 代碼
fn external_propose(origin: OriginFor<T>, proposal_hash: T::Hash)
- 參數(shù)
-
proposal_hash
提案hash
-
- 邏輯
-
NextExternal
不存在 - 如果在黑名單中赡盘, 那么過期時間到才能操作
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SuperMajorityApprove));
-
這個可能是用來快速把提案送到公投隊列
- 代碼
-
todo
- 代碼
pub fn external_propose_majority( origin: OriginFor<T>, proposal_hash: T::Hash, )
- 參數(shù)
-
proposal_hash
提案hash
-
- 邏輯
- 3/4議會權(quán)限
- 強制更改
NextExternal
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SimpleMajority));
- 代碼
-
todo
- 代碼
pub fn external_propose_default( origin: OriginFor<T>, proposal_hash: T::Hash, )
- 參數(shù)
-
proposal_hash
提案hash
-
- 邏輯
- 1/1議會權(quán)限
- 強制更改
NextExternal
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SuperMajorityAgainst))
- 代碼
-
快速通道(把提案迅速提到公投)
- 代碼
pub fn fast_track( origin: OriginFor<T>, proposal_hash: T::Hash, voting_period: T::BlockNumber, delay: T::BlockNumber, )
- 參數(shù)
-
proposal_hash
提案hash -
voting_period
多久開始 -
delay
開始后多久結(jié)束
-
- 邏輯
- 技術(shù)委員會權(quán)限(至少2/3)
-
NextExternal
存在 -
VoteThreshold::SuperMajorityApprove
這個不能走快速通道 <NextExternal<T>>::kill();
- 代碼
-
終止外部提案
- 代碼
pub fn veto_external(origin: OriginFor<T>, proposal_hash: T::Hash)
- 參數(shù)
-
proposal_hash
提案hash
-
- 邏輯
- 任一技術(shù)委員會成員
-
NextExternal
存在 - 把提案列入黑名單
- 代碼
-
取消一個公投
- 代碼 `pub fn cancel_referendum(
origin: OriginFor<T>,[pallet::compact] ref_index: ReferendumIndex,
)` - 參數(shù)
-
ref_index
公投索引
-
- 邏輯
- root權(quán)限
- 刪除公投信息
- 代碼 `pub fn cancel_referendum(
-
取消一個正在等待通過的公投
pub fn cancel_queued(origin: OriginFor<T>, which: ReferendumIndex)
輔助方法
- 執(zhí)行方法(公投通過)
- 代碼
fn do_enact_proposal(proposal_hash: T::Hash, index: ReferendumIndex) -> DispatchResult
- 代碼