Skip to content

Commit

Permalink
feat(minor-ampd): stellar verifier set verifier (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx authored Sep 11, 2024
1 parent 0da965d commit 2d4a99c
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ serde_json = { workspace = true }
serde_with = "3.2.0"
service-registry = { workspace = true }
sha3 = { workspace = true }
stellar = { workspace = true }
stellar-rs = "0.3.2"
stellar-xdr = { workspace = true, features = ["serde_json"] }
sui-gateway = { workspace = true }
Expand Down
14 changes: 13 additions & 1 deletion ampd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ mod tests {
type = 'StellarMsgVerifier'
cosmwasm_contract = '{}'
http_url = 'http://localhost:8000'
[[handlers]]
type = 'StellarVerifierSetVerifier'
cosmwasm_contract = '{}'
http_url = 'http://localhost:8000'
",
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
Expand All @@ -135,10 +140,11 @@ mod tests {
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
);

let cfg: Config = toml::from_str(config_str.as_str()).unwrap();
assert_eq!(cfg.handlers.len(), 9);
assert_eq!(cfg.handlers.len(), 10);
}

#[test]
Expand Down Expand Up @@ -336,6 +342,12 @@ mod tests {
),
http_url: Url::from_str("http://127.0.0.1").unwrap(),
},
HandlerConfig::StellarVerifierSetVerifier {
cosmwasm_contract: TMAddress::from(
AccountId::new("axelar", &[0u8; 32]).unwrap(),
),
http_url: Url::from_str("http://127.0.0.1").unwrap(),
},
],
..Config::default()
}
Expand Down
21 changes: 21 additions & 0 deletions ampd/src/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub enum Config {
cosmwasm_contract: TMAddress,
http_url: Url,
},
StellarVerifierSetVerifier {
cosmwasm_contract: TMAddress,
http_url: Url,
},
}

fn validate_multisig_signer_config<'de, D>(configs: &[Config]) -> Result<(), D::Error>
Expand Down Expand Up @@ -202,6 +206,22 @@ where
}
}

fn validate_stellar_verifier_set_verifier_config<'de, D>(configs: &[Config]) -> Result<(), D::Error>
where
D: Deserializer<'de>,
{
match configs
.iter()
.filter(|config| matches!(config, Config::StellarMsgVerifier { .. }))
.count()
{
count if count > 1 => Err(de::Error::custom(
"only one Stellar verifier set verifier config is allowed",
)),
_ => Ok(()),
}
}

pub fn deserialize_handler_configs<'de, D>(deserializer: D) -> Result<Vec<Config>, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -216,6 +236,7 @@ where
validate_mvx_msg_verifier_config::<D>(&configs)?;
validate_mvx_worker_set_verifier_config::<D>(&configs)?;
validate_stellar_msg_verifier_config::<D>(&configs)?;
validate_stellar_verifier_set_verifier_config::<D>(&configs)?;

Ok(configs)
}
Expand Down
1 change: 1 addition & 0 deletions ampd/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod multisig;
pub mod mvx_verify_msg;
pub mod mvx_verify_verifier_set;
pub(crate) mod stellar_verify_msg;
pub(crate) mod stellar_verify_verifier_set;
pub mod sui_verify_msg;
pub mod sui_verify_verifier_set;

Expand Down
Loading

0 comments on commit 2d4a99c

Please sign in to comment.