Skip to content

Commit

Permalink
Merge pull request #84 from confio/66-valset-enhance-metadata-validation
Browse files Browse the repository at this point in the history
Valset: metadata validation
  • Loading branch information
ueco-jb committed Feb 9, 2022
2 parents ac0cc6e + 6f6af3e commit 58bc19f
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 139 deletions.
3 changes: 3 additions & 0 deletions contracts/tgrade-valset/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn instantiate(
for op in msg.initial_keys.into_iter() {
let oper = deps.api.addr_validate(&op.operator)?;
let pubkey: Ed25519Pubkey = op.validator_pubkey.try_into()?;
op.metadata.validate()?;
let info = OperatorInfo {
pubkey,
metadata: op.metadata,
Expand Down Expand Up @@ -205,6 +206,8 @@ fn execute_register_validator_key(
pubkey: Pubkey,
metadata: ValidatorMetadata,
) -> Result<Response, ContractError> {
metadata.validate()?;

let pubkey: Ed25519Pubkey = pubkey.try_into()?;
let moniker = metadata.moniker.clone();

Expand Down
13 changes: 10 additions & 3 deletions contracts/tgrade-valset/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ pub enum ContractError {
#[error("Scaling must be unset or greater than zero")]
InvalidScaling {},

#[error("The moniker field must not be empty")]
InvalidMoniker {},

#[error("Tendermint pubkey must be 32 bytes long")]
InvalidPubkey {},

Expand Down Expand Up @@ -71,6 +68,16 @@ pub enum ContractError {

#[error("Jail did not yet expire")]
JailDidNotExpire {},

#[error("Invalid metadata - {data} length must be {min}-{max} characters")]
InvalidMetadata {
data: &'static str,
min: usize,
max: usize,
},

#[error("Invalid metadata - website needs to start with http:// or https://")]
InvalidMetadataWebsitePrefix {},
}

impl From<Ed25519PubkeyConversionError> for ContractError {
Expand Down
Loading

0 comments on commit 58bc19f

Please sign in to comment.