made 'owner' field optional to prepare for its future removal

This commit is contained in:
Jędrzej Stuczyński
2024-09-04 09:55:23 +01:00
parent e76c8e06be
commit ed7a84a1ce
7 changed files with 21 additions and 10 deletions
@@ -190,7 +190,8 @@ pub struct ContractState {
#[deprecated(
note = "use explicit ADMIN instead. this field will be removed in future release"
)]
pub owner: Addr,
#[serde(default)]
pub owner: Option<Addr>,
/// Address of "rewarding validator" (nym-api) that's allowed to send any rewarding-related transactions.
pub rewarding_validator_address: Addr,
@@ -8190,7 +8190,6 @@
"description": "The current state of the mixnet contract.",
"type": "object",
"required": [
"owner",
"params",
"rewarding_denom",
"rewarding_validator_address",
@@ -8199,10 +8198,14 @@
"properties": {
"owner": {
"description": "Address of the contract owner.",
"default": null,
"deprecated": true,
"allOf": [
"anyOf": [
{
"$ref": "#/definitions/Addr"
},
{
"type": "null"
}
]
},
@@ -4,7 +4,6 @@
"description": "The current state of the mixnet contract.",
"type": "object",
"required": [
"owner",
"params",
"rewarding_denom",
"rewarding_validator_address",
@@ -13,10 +12,14 @@
"properties": {
"owner": {
"description": "Address of the contract owner.",
"default": null,
"deprecated": true,
"allOf": [
"anyOf": [
{
"$ref": "#/definitions/Addr"
},
{
"type": "null"
}
]
},
+2 -2
View File
@@ -31,7 +31,7 @@ fn default_initial_state(
// we have to temporarily preserve this functionalities until it can be removed
#[allow(deprecated)]
ContractState {
owner,
owner: Some(owner),
rewarding_validator_address,
vesting_contract_address,
rewarding_denom: rewarding_denom.clone(),
@@ -607,7 +607,7 @@ mod tests {
#[allow(deprecated)]
let expected_state = ContractState {
owner: Addr::unchecked("sender"),
owner: Some(Addr::unchecked("sender")),
rewarding_validator_address: Addr::unchecked("foomp123"),
vesting_contract_address: Addr::unchecked("bar456"),
rewarding_denom: "uatom".into(),
@@ -44,7 +44,7 @@ pub(crate) mod tests {
#[allow(deprecated)]
let dummy_state = ContractState {
owner: Addr::unchecked("foomp"),
owner: Some(Addr::unchecked("foomp")),
rewarding_validator_address: Addr::unchecked("monitor"),
vesting_contract_address: Addr::unchecked("foomp"),
rewarding_denom: "unym".to_string(),
@@ -25,7 +25,7 @@ pub fn try_update_contract_admin(
// during 'execute_update_admin' call
#[allow(deprecated)]
storage::CONTRACT_STATE.update(deps.storage, |mut state| -> StdResult<_> {
state.owner = new_admin;
state.owner = Some(new_admin);
Ok(state)
})?;
+5 -1
View File
@@ -54,9 +54,13 @@ pub(crate) fn vesting_purge(deps: DepsMut) -> Result<(), MixnetContractError> {
pub(crate) fn explicit_contract_admin(deps: DepsMut) -> Result<(), MixnetContractError> {
// we need to read the deprecated field to migrate it over
#[allow(deprecated)]
// SAFETY: this value should ALWAYS exist on the first execution of this migration;
// as a matter of fact, it should ALWAYS continue existing until another migration
#[allow(clippy::expect_used)]
let existing_admin = mixnet_params_storage::CONTRACT_STATE
.load(deps.storage)?
.owner;
.owner
.expect("the contract state is corrupt - there's no admin set");
mixnet_params_storage::ADMIN.set(deps, Some(existing_admin))?;
Ok(())
}