Skip to content

Commit

Permalink
add new proposal type to update only the default vote policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ctindogarus4f committed Jan 13, 2022
1 parent d9502b8 commit 009bdac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sputnikdao2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ ProposalKind::ChangeConfig { .. },
ProposalKind::ChangePolicy { .. },
ProposalKind::ChangePolicyAddOrUpdateRole { .. },
ProposalKind::ChangePolicyRemoveRole { .. },
ProposalKind::ChangePolicyUpdateDefaultVotePolicy { .. },
ProposalKind::AddMemberToRole { .. },
ProposalKind::RemoveMemberFromRole { .. },
ProposalKind::FunctionCall { .. },
Expand All @@ -276,8 +277,9 @@ ProposalKind::FactoryInfoUpdate { .. },

- **ChangeConfig** - used to change the configuration of the DAO
- **ChangePolicy** - used to change the full policy of the DAO
- **ChangePolicyAddOrUpdateRole** - used to add a new role to the policy. If the role already exists, update it.
- **ChangePolicyRemoveRole** - used to remove a role from the policy.
- **ChangePolicyAddOrUpdateRole** - used to add a new role to the policy of the DAO. If the role already exists, update it.
- **ChangePolicyRemoveRole** - used to remove a role from the policy of the DAO.
- **ChangePolicyUpdateDefaultVotePolicy** - used to update the default vote policy from the policy of the DAO.
- **AddMemberToRole** - used to add a member to a role in the DAO
- **RemoveMemberFromRole** - used to remove a member from a role in the DAO
- **FunctionCall** - used to a call a function on any valid account on the network including the DAO itself, any other DAO, or any other contract. This is a useful mechanism for extending the capabilities of the DAO without modifying or complicating the DAO contract code. One can imagine a family of contracts built specifically to serve the DAO as agents, proxies, oracles and banks, for example.
Expand Down
Binary file modified sputnikdao2/res/sputnikdao2.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions sputnikdao2/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ impl Policy {
env::log_str(&format!("ERR_ROLE_NOT_FOUND:{}", role));
}

pub fn update_default_vote_policy(&mut self, vote_policy: &VotePolicy) {
self.default_vote_policy = vote_policy.clone();
env::log_str("Successfully updated the default vote policy.");
}

pub fn add_member_to_role(&mut self, role: &String, member_id: &AccountId) {
for i in 0..self.roles.len() {
if &self.roles[i].name == role {
Expand Down
11 changes: 11 additions & 0 deletions sputnikdao2/src/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum ProposalKind {
ChangePolicyAddOrUpdateRole { role: RolePermission },
/// Remove role from the policy. This is short cut to updating the whole policy.
ChangePolicyRemoveRole { role: String },
/// Update the default vote policy from the policy. This is short cut to updating the whole policy.
ChangePolicyUpdateDefaultVotePolicy { vote_policy: VotePolicy },
/// Add member to given role in the policy. This is short cut to updating the whole policy.
AddMemberToRole { member_id: AccountId, role: String },
/// Remove member to given role in the policy. This is short cut to updating the whole policy.
Expand Down Expand Up @@ -106,6 +108,9 @@ impl ProposalKind {
ProposalKind::ChangePolicy { .. } => "policy",
ProposalKind::ChangePolicyAddOrUpdateRole { .. } => "policy_add_or_update_role",
ProposalKind::ChangePolicyRemoveRole { .. } => "policy_remove_role",
ProposalKind::ChangePolicyUpdateDefaultVotePolicy { .. } => {
"policy_update_default_vote_policy"
}
ProposalKind::AddMemberToRole { .. } => "add_member_to_role",
ProposalKind::RemoveMemberFromRole { .. } => "remove_member_from_role",
ProposalKind::FunctionCall { .. } => "call",
Expand Down Expand Up @@ -305,6 +310,12 @@ impl Contract {
self.policy.set(&VersionedPolicy::Current(new_policy));
PromiseOrValue::Value(())
}
ProposalKind::ChangePolicyUpdateDefaultVotePolicy { vote_policy } => {
let mut new_policy = policy.clone();
new_policy.update_default_vote_policy(vote_policy);
self.policy.set(&VersionedPolicy::Current(new_policy));
PromiseOrValue::Value(())
}
ProposalKind::AddMemberToRole { member_id, role } => {
let mut new_policy = policy.clone();
new_policy.add_member_to_role(role, &member_id.clone().into());
Expand Down

0 comments on commit 009bdac

Please sign in to comment.