Skip to content

Commit

Permalink
Support base58 in matching list (#2717)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
mattiekat committed Sep 8, 2023
1 parent d7da566 commit 892cc5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions rust/agents/relayer/src/settings/matching_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
)
}

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion typescript/sdk/src/metadata/customZodTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})$/,
);

0 comments on commit 892cc5d

Please sign in to comment.