multiversx_sc_modules/governance/
governance_configurable.rsmultiversx_sc::imports!();
#[multiversx_sc::module]
pub trait GovernanceConfigurablePropertiesModule {
fn init_governance_module(
&self,
governance_token_id: TokenIdentifier,
quorum: BigUint,
min_token_balance_for_proposal: BigUint,
voting_delay_in_blocks: u64,
voting_period_in_blocks: u64,
lock_time_after_voting_ends_in_blocks: u64,
) {
require!(
governance_token_id.is_valid_esdt_identifier(),
"Invalid ESDT token ID provided for governance_token_id"
);
self.governance_token_id()
.set_if_empty(&governance_token_id);
self.try_change_quorum(quorum);
self.try_change_min_token_balance_for_proposing(min_token_balance_for_proposal);
self.try_change_voting_delay_in_blocks(voting_delay_in_blocks);
self.try_change_voting_period_in_blocks(voting_period_in_blocks);
self.try_change_lock_time_after_voting_ends_in_blocks(
lock_time_after_voting_ends_in_blocks,
);
}
#[endpoint(changeQuorum)]
fn change_quorum(&self, new_value: BigUint) {
self.require_caller_self();
self.try_change_quorum(new_value);
}
#[endpoint(changeMinTokenBalanceForProposing)]
fn change_min_token_balance_for_proposing(&self, new_value: BigUint) {
self.require_caller_self();
self.try_change_min_token_balance_for_proposing(new_value);
}
#[endpoint(changeVotingDelayInBlocks)]
fn change_voting_delay_in_blocks(&self, new_value: u64) {
self.require_caller_self();
self.try_change_voting_delay_in_blocks(new_value);
}
#[endpoint(changeVotingPeriodInBlocks)]
fn change_voting_period_in_blocks(&self, new_value: u64) {
self.require_caller_self();
self.try_change_voting_period_in_blocks(new_value);
}
#[endpoint(changeLockTimeAfterVotingEndsInBlocks)]
fn change_lock_time_after_voting_ends_in_blocks(&self, new_value: u64) {
self.require_caller_self();
self.try_change_lock_time_after_voting_ends_in_blocks(new_value);
}
fn require_caller_self(&self) {
let caller = self.blockchain().get_caller();
let sc_address = self.blockchain().get_sc_address();
require!(
caller == sc_address,
"Only the SC itself may call this function"
);
}
fn try_change_quorum(&self, new_value: BigUint) {
require!(new_value != 0, "Quorum can't be set to 0");
self.quorum().set(&new_value);
}
fn try_change_min_token_balance_for_proposing(&self, new_value: BigUint) {
require!(
new_value != 0,
"Min token balance for proposing can't be set to 0"
);
self.min_token_balance_for_proposing().set(&new_value);
}
fn try_change_voting_delay_in_blocks(&self, new_value: u64) {
require!(new_value != 0, "Voting delay in blocks can't be set to 0");
self.voting_delay_in_blocks().set(new_value);
}
fn try_change_voting_period_in_blocks(&self, new_value: u64) {
require!(
new_value != 0,
"Voting period (in blocks) can't be set to 0"
);
self.voting_period_in_blocks().set(new_value);
}
fn try_change_lock_time_after_voting_ends_in_blocks(&self, new_value: u64) {
require!(
new_value != 0,
"Lock time after voting ends (in blocks) can't be set to 0"
);
self.lock_time_after_voting_ends_in_blocks().set(new_value);
}
#[view(getGovernanceTokenId)]
#[storage_mapper("governance:governanceTokenId")]
fn governance_token_id(&self) -> SingleValueMapper<TokenIdentifier>;
#[view(getQuorum)]
#[storage_mapper("governance:quorum")]
fn quorum(&self) -> SingleValueMapper<BigUint>;
#[view(getMinFeeForPropose)]
#[storage_mapper("minFeeForPropose")]
fn min_fee_for_propose(&self) -> SingleValueMapper<BigUint>;
#[view(getMinTokenBalanceForProposing)]
#[storage_mapper("governance:minTokenBalanceForProposing")]
fn min_token_balance_for_proposing(&self) -> SingleValueMapper<BigUint>;
#[view(getVotingDelayInBlocks)]
#[storage_mapper("governance:votingDelayInBlocks")]
fn voting_delay_in_blocks(&self) -> SingleValueMapper<u64>;
#[view(getVotingPeriodInBlocks)]
#[storage_mapper("governance:votingPeriodInBlocks")]
fn voting_period_in_blocks(&self) -> SingleValueMapper<u64>;
#[view(getLockTimeAfterVotingEndsInBlocks)]
#[storage_mapper("governance:lockTimeAfterVotingEndsInBlocks")]
fn lock_time_after_voting_ends_in_blocks(&self) -> SingleValueMapper<u64>;
}