Skip to content

Commit 513cd0a

Browse files
committed
Update eip155 handling
1 parent c06b7e8 commit 513cd0a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/shared/src/models/eip155/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,34 @@ mod tests {
229229

230230
assert_eq!(data, "https://i.seadn.io/gae/hKHZTZSTmcznonu8I6xcVZio1IF76fq0XmcxnvUykC-FGuVJ75UPdLDlKJsfgVXH9wOSmkyHw0C39VAYtsGyxT7WNybjQ6s3fM3macE?w=500&auto=format".to_string());
231231
}
232+
233+
#[tokio::test]
234+
async fn test_calldata_avatar_erc1155z() {
235+
let provider = Provider::<Http>::try_from("https://rpc.ankr.com/eth")
236+
.unwrap()
237+
.wrap_into(|it| CCIPReadMiddleware::new(Arc::from(it)));
238+
239+
let state = LookupState {
240+
rpc: Arc::new(provider),
241+
opensea_api_key: "".to_string(),
242+
ipfs_gateway: "https://ipfs.io/ipfs/".to_string(),
243+
arweave_gateway: "https://arweave.net/".to_string(),
244+
};
245+
246+
let data = resolve_eip155(
247+
ChainId::Ethereum,
248+
EIP155ContractType::ERC1155,
249+
"0x495f947276749ce646f68ac8c248420045cb7b5e",
250+
U256::from_dec_str("109791375735522898048150917964456965919994596086232976516654423066184641413121").unwrap(),
251+
&state,
252+
)
253+
.await
254+
.unwrap();
255+
256+
assert_eq!(
257+
data,
258+
"https://i.seadn.io/gae/Ra4OPR25gZ-_c7yasr7-vwUHxJp9SSn_w3angBICNK7qlUX63g0YlcFqQc5dVC47atikih_JkjMsfX4xE4KJURsbFcP-9y1cZWx4?w=500&auto=format"
259+
.to_string()
260+
);
261+
}
232262
}

packages/shared/src/models/lookup/image.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lazy_static! {
2020
static ref ARWEAVE_REGEX: regex::Regex =
2121
regex::Regex::new(r"^ar://(.+)").expect("should be a valid regex");
2222
static ref EIP155_REGEX: regex::Regex =
23-
regex::Regex::new(r"eip155:([0-9]+)/(erc1155|erc721):0x([0-9a-fA-F]{40})/([0-9]+)")
23+
regex::Regex::new(r"(?i:eip155):([0-9]+)/(?i:(erc1155|erc721)):0x([0-9a-fA-F]{40})/([0-9]+)")
2424
.expect("should be a valid regex");
2525
}
2626
#[derive(Error, Debug)]
@@ -71,12 +71,15 @@ pub async fn decode(data: &[u8], state: &LookupState) -> Result<String, ENSLooku
7171
return Ok(value.to_string());
7272
};
7373

74+
info!("EIP155: {captures:?}");
75+
7476
let (Some(chain_id), Some(contract_type), Some(contract_address), Some(token_id)) = (
7577
captures.get(1),
7678
captures.get(2),
7779
captures.get(3),
7880
captures.get(4),
7981
) else {
82+
info!("Failed to decode EIP155: {value}");
8083
return Err(ENSLookupError::AbiDecodeError);
8184
};
8285

@@ -88,7 +91,7 @@ pub async fn decode(data: &[u8], state: &LookupState) -> Result<String, ENSLooku
8891
let token_id = U256::from_dec_str(token_id.as_str())
8992
.map_err(|err| ImageLookupError::FormatError(err.to_string()))?;
9093

91-
let contract_type = match contract_type.as_str() {
94+
let contract_type = match contract_type.as_str().to_lowercase().as_str() {
9295
"erc721" => EIP155ContractType::ERC721,
9396
"erc1155" => EIP155ContractType::ERC1155,
9497
_ => return Err(ImageLookupError::FormatError("invalid contract type".to_string()).into()),

0 commit comments

Comments
 (0)