Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support base58 in matching list #2717

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})$/,
);