-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2019-2025 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use super::types::EthAddress; | ||
use crate::shim::address::Address as FilecoinAddress; | ||
use crate::shim::state_tree::StateTree; | ||
use anyhow::Result; | ||
use fvm_ipld_blockstore::Blockstore; | ||
|
||
pub fn lookup_eth_address<DB: Blockstore>( | ||
addr: &FilecoinAddress, | ||
state: &StateTree<DB>, | ||
) -> Result<Option<EthAddress>> { | ||
// Attempt to convert directly, if it's an f4 address. | ||
if let Ok(eth_addr) = EthAddress::from_filecoin_address(addr) { | ||
if !eth_addr.is_masked_id() { | ||
return Ok(Some(eth_addr)); | ||
} | ||
} | ||
|
||
// Otherwise, resolve the ID addr. | ||
let id_addr = match state.lookup_id(addr)? { | ||
Some(id) => id, | ||
_ => return Ok(None), | ||
}; | ||
|
||
// Lookup on the target actor and try to get an f410 address. | ||
let result = state.get_actor(addr); | ||
if let Ok(Some(actor_state)) = result { | ||
if let Some(addr) = actor_state.delegated_address { | ||
if let Ok(eth_addr) = EthAddress::from_filecoin_address(&addr.into()) { | ||
if !eth_addr.is_masked_id() { | ||
// Conversable into an eth address, use it. | ||
return Ok(Some(eth_addr)); | ||
} | ||
} | ||
} else { | ||
// No delegated address -> use a masked ID address | ||
} | ||
} else if let Ok(None) = result { | ||
// Not found -> use a masked ID address | ||
} else { | ||
// Any other error -> fail. | ||
result?; | ||
} | ||
|
||
// Otherwise, use the masked address. | ||
Ok(Some(EthAddress::from_actor_id(id_addr))) | ||
} |