Skip to content

Commit

Permalink
Merge pull request #188 from confio/158-promotetoprivileged
Browse files Browse the repository at this point in the history
Add promote / demote contract to privileged gov proposals

Add set / clear migrate admin gov proposals
  • Loading branch information
maurolacy authored Sep 21, 2022
2 parents 3f9d2cf + 64b454f commit 8b0ab53
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
34 changes: 34 additions & 0 deletions contracts/tgrade-validator-voting/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ pub fn execute_execute<Q: CustomQuery>(
proposal: GovProposal::ChangeParams(params),
})
}
PromoteToPrivilegedContract { contract } => {
res = res.add_message(TgradeMsg::ExecuteGovProposal {
title: proposal.title,
description: proposal.description,
proposal: GovProposal::PromoteToPrivilegedContract { contract },
})
}
DemotePrivilegedContract { contract } => {
res = res.add_message(TgradeMsg::ExecuteGovProposal {
title: proposal.title,
description: proposal.description,
proposal: GovProposal::DemotePrivilegedContract { contract },
})
}
SetContractAdmin {
contract,
new_admin,
} => {
res = res.add_message(TgradeMsg::ExecuteGovProposal {
title: proposal.title,
description: proposal.description,
proposal: GovProposal::SetContractAdmin {
contract,
new_admin,
},
})
}
ClearContractAdmin { contract } => {
res = res.add_message(TgradeMsg::ExecuteGovProposal {
title: proposal.title,
description: proposal.description,
proposal: GovProposal::ClearContractAdmin { contract },
})
}
};

Ok(res
Expand Down
3 changes: 3 additions & 0 deletions contracts/tgrade-validator-voting/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum ContractError {

#[error("Invalid consensus params: All cannot be none")]
InvalidConsensusParams {},

#[error("Empty new admin")]
EmptyAdmin {},
}

impl From<tg_voting_contract::ContractError> for ContractError {
Expand Down
18 changes: 18 additions & 0 deletions contracts/tgrade-validator-voting/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ pub enum ValidatorProposal {
Text {},
/// Defines a proposal to change one or more parameters.
ChangeParams(Vec<ParamChange>),
PromoteToPrivilegedContract {
/// The contract address to be promoted
contract: String,
},
DemotePrivilegedContract {
/// The contract address to be demoted
contract: String,
},
SetContractAdmin {
/// The contract address to be updated
contract: String,
/// The account address to become migrate admin of this contract
new_admin: String,
},
ClearContractAdmin {
/// The contract address to be cleared
contract: String,
},
}

// We can also add this as a tg3 extension
Expand Down
14 changes: 13 additions & 1 deletion contracts/tgrade-validator-voting/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ impl ValidatorProposal {
return Err(ContractError::InvalidConsensusParams {});
}
}
ValidatorProposal::CancelUpgrade {} | ValidatorProposal::Text {} => {}
ValidatorProposal::SetContractAdmin {
contract: _contract,
new_admin,
} => {
if new_admin.is_empty() {
return Err(ContractError::EmptyAdmin {});
}
}
ValidatorProposal::ClearContractAdmin { .. }
| ValidatorProposal::PromoteToPrivilegedContract { .. }
| ValidatorProposal::DemotePrivilegedContract { .. }
| ValidatorProposal::CancelUpgrade {}
| ValidatorProposal::Text {} => {}
}
Ok(())
}
Expand Down

0 comments on commit 8b0ab53

Please sign in to comment.