Support base58 in matching list (#2717)

### Description
Fixes a current deployment issue due to some changes in the infra
deployment.

Also caught an error in the schema for the matching list type and
updated it.
pull/2726/head
Mattie Conover 1 year ago committed by GitHub
parent d7da566e75
commit 892cc5df9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      rust/agents/relayer/src/settings/matching_list.rs
  2. 2
      typescript/sdk/src/metadata/customZodTypes.ts

@ -8,7 +8,7 @@ use std::{
marker::PhantomData,
};
use hyperlane_core::{config::StrOrInt, HyperlaneMessage, H160, H256};
use hyperlane_core::{config::StrOrInt, utils::hex_or_base58_to_h256, HyperlaneMessage, H256};
use serde::{
de::{Error, SeqAccess, Visitor},
Deserialize, Deserializer,
@ -118,7 +118,7 @@ impl<'de> Visitor<'de> for FilterVisitor<H256> {
fn expecting(&self, fmt: &mut Formatter) -> fmt::Result {
write!(
fmt,
"Expecting either a wildcard \"*\", hex address string, or list of hex address strings"
"Expecting either a wildcard \"*\", hex/base58 address string, or list of hex/base58 address strings"
)
}
@ -254,12 +254,7 @@ fn to_serde_err<IE: ToString, OE: Error>(e: IE) -> OE {
}
fn parse_addr<E: Error>(addr_str: &str) -> Result<H256, E> {
if addr_str.len() <= 42 {
addr_str.parse::<H160>().map(H256::from)
} else {
addr_str.parse::<H256>()
}
.map_err(to_serde_err)
hex_or_base58_to_h256(addr_str).map_err(to_serde_err)
}
#[cfg(test)]
@ -312,7 +307,7 @@ mod test {
#[test]
fn config_with_address() {
let list: MatchingList = serde_json::from_str(r#"[{"senderAddress": "0x9d4454B023096f34B160D6B654540c56A1F81688", "recipientAddress": "9d4454B023096f34B160D6B654540c56A1F81688"}]"#).unwrap();
let list: MatchingList = serde_json::from_str(r#"[{"senderAddress": "0x9d4454B023096f34B160D6B654540c56A1F81688", "recipientAddress": "0x9d4454B023096f34B160D6B654540c56A1F81688"}]"#).unwrap();
assert!(list.0.is_some());
assert_eq!(list.0.as_ref().unwrap().len(), 1);
let elem = &list.0.as_ref().unwrap()[0];
@ -389,4 +384,11 @@ mod test {
// blacklist use
assert!(!MatchingList(None).matches(info, false));
}
#[test]
fn supports_base58() {
serde_json::from_str::<MatchingList>(
r#"[{"originDomain":1399811151,"senderAddress":"DdTMkk9nuqH5LnD56HLkPiKMV3yB3BNEYSQfgmJHa5i7","destinationDomain":11155111,"recipientAddress":"0x6AD4DEBA8A147d000C09de6465267a9047d1c217"}]"#,
).unwrap();
}
}

@ -14,5 +14,5 @@ export const ZUWei = z.union([ZUint.safe(), z.string().regex(/^\d+$/)]);
export const ZHash = z
.string()
.regex(
/^(0x[0-9a-fA-F]{32}|[0-9a-fA-F]{40}|[0-9a-fA-F]{64}|[0-9a-fA-F]{128})|([123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{32})$/,
/^(0x([0-9a-fA-F]{32}|[0-9a-fA-F]{40}|[0-9a-fA-F]{64}|[0-9a-fA-F]{128}))|([123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{32})$/,
);

Loading…
Cancel
Save