Skip to content

Commit d1a20c4

Browse files
mriiseshamb0
authored andcommitted
rename evm actor's Address to EthAddress (filecoin-project#665)
rename evm actor's type to
1 parent 332a107 commit d1a20c4

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

actors/evm/src/interpreter/address.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use fvm_shared::address::Address as FilecoinAddress;
66
///
77
/// TODO this type will eventually handle f4 address detection.
88
#[derive(PartialEq, Eq, Clone)]
9-
pub struct Address([u8; 20]);
9+
pub struct EthAddress([u8; 20]);
1010

11-
impl TryFrom<U256> for Address {
11+
impl TryFrom<U256> for EthAddress {
1212
type Error = StatusCode;
1313

1414
fn try_from(v: U256) -> Result<Self, Self::Error> {
@@ -24,24 +24,24 @@ impl TryFrom<U256> for Address {
2424
}
2525
}
2626

27-
impl std::fmt::Debug for Address {
27+
impl std::fmt::Debug for EthAddress {
2828
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2929
f.write_str(&hex::encode(self.0))
3030
}
3131
}
3232

33-
impl Address {
33+
impl EthAddress {
3434
/// Expect a Filecoin address type containing an ID address, and return an address in EVM-form.
35-
pub fn from_id_address(addr: &FilecoinAddress) -> Option<Address> {
36-
addr.id().ok().map(Address::from_id)
35+
pub fn from_id_address(addr: &FilecoinAddress) -> Option<EthAddress> {
36+
addr.id().ok().map(EthAddress::from_id)
3737
}
3838

3939
/// Returns an EVM-form ID address from actor ID.
40-
pub fn from_id(id: u64) -> Address {
40+
pub fn from_id(id: u64) -> EthAddress {
4141
let mut bytes = [0u8; 20];
4242
bytes[0] = 0xff;
4343
bytes[12..].copy_from_slice(&id.to_be_bytes());
44-
Address(bytes)
44+
EthAddress(bytes)
4545
}
4646

4747
/// Interpret the hash as an ID address in EVM-form, and return a Filecoin ID address if that's
@@ -67,7 +67,7 @@ impl Address {
6767

6868
#[cfg(test)]
6969
mod tests {
70-
use crate::interpreter::address::Address;
70+
use crate::interpreter::address::EthAddress;
7171
use crate::U256;
7272
use fvm_shared::address::Address as FilecoinAddress;
7373

@@ -82,15 +82,15 @@ mod tests {
8282
#[test]
8383
fn $name() {
8484
let evm_bytes = $input.concat();
85-
let evm_addr = Address::try_from(U256::from(evm_bytes.as_slice())).unwrap();
85+
let evm_addr = EthAddress::try_from(U256::from(evm_bytes.as_slice())).unwrap();
8686
assert_eq!(
8787
evm_addr.as_id_address(),
8888
$expectation
8989
);
9090

9191
// test inverse conversion, if a valid ID address was supplied
9292
if let Some(fil_addr) = $expectation {
93-
assert_eq!(Address::from_id_address(&fil_addr), Some(evm_addr));
93+
assert_eq!(EthAddress::from_id_address(&fil_addr), Some(evm_addr));
9494
}
9595
}
9696
)*

actors/evm/src/interpreter/instructions/call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
super::memory::{copy_to_memory, get_memory_region},
3-
crate::interpreter::address::Address,
3+
crate::interpreter::address::EthAddress,
44
crate::interpreter::instructions::memory::MemoryRegion,
55
crate::interpreter::output::StatusCode,
66
crate::interpreter::precompiles,
@@ -153,7 +153,7 @@ pub fn call<'r, BS: Blockstore, RT: Runtime<BS>>(
153153
.map_err(|_| StatusCode::PrecompileFailure)?;
154154
Ok(RawBytes::from(result))
155155
} else {
156-
let dst_addr = Address::try_from(dst)?
156+
let dst_addr = EthAddress::try_from(dst)?
157157
.as_id_address()
158158
.ok_or_else(|| StatusCode::BadAddress("not an actor id address".to_string()))?;
159159

@@ -222,7 +222,7 @@ pub fn callactor<'r, BS: Blockstore, RT: Runtime<BS>>(
222222
.map_err(|_| StatusCode::InvalidMemoryAccess)?;
223223

224224
let result = {
225-
let dst_addr = Address::try_from(dst)?
225+
let dst_addr = EthAddress::try_from(dst)?
226226
.as_id_address()
227227
.ok_or_else(|| StatusCode::BadAddress(format!("not an actor id address: {}", dst)))?;
228228

actors/evm/src/interpreter/instructions/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::interpreter::address::Address;
1+
use crate::interpreter::address::EthAddress;
22
use {
33
crate::interpreter::{ExecutionState, StatusCode, System, U256},
44
fil_actors_runtime::runtime::Runtime,
@@ -19,7 +19,7 @@ pub fn caller<'r, BS: Blockstore, RT: Runtime<BS>>(
1919
platform: &'r System<'r, BS, RT>,
2020
) {
2121
let id = platform.rt.message().caller().id().unwrap();
22-
state.stack.push(Address::from_id(id).as_evm_word())
22+
state.stack.push(EthAddress::from_id(id).as_evm_word())
2323
}
2424

2525
#[inline]
@@ -28,7 +28,7 @@ pub fn address<'r, BS: Blockstore, RT: Runtime<BS>>(
2828
platform: &'r System<'r, BS, RT>,
2929
) {
3030
let id = platform.rt.message().receiver().id().unwrap();
31-
state.stack.push(Address::from_id(id).as_evm_word())
31+
state.stack.push(EthAddress::from_id(id).as_evm_word())
3232
}
3333

3434
#[inline]
@@ -37,7 +37,7 @@ pub fn origin<'r, BS: Blockstore, RT: Runtime<BS>>(
3737
platform: &'r System<'r, BS, RT>,
3838
) {
3939
let id = platform.rt.message().origin().id().unwrap();
40-
state.stack.push(Address::from_id(id).as_evm_word())
40+
state.stack.push(EthAddress::from_id(id).as_evm_word())
4141
}
4242

4343
#[inline]

actors/evm/src/interpreter/instructions/ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::interpreter::address::Address;
1+
use crate::interpreter::address::EthAddress;
22
use crate::interpreter::instructions::memory::copy_to_memory;
33
use crate::U256;
44
use cid::Cid;
@@ -61,7 +61,7 @@ fn get_evm_bytecode_cid<BS: Blockstore, RT: Runtime<BS>>(
6161
rt: &RT,
6262
addr: U256,
6363
) -> Result<Cid, StatusCode> {
64-
let addr = Address::try_from(addr)?
64+
let addr = EthAddress::try_from(addr)?
6565
.as_id_address()
6666
.ok_or_else(|| StatusCode::BadAddress("no support for non-ID addresses yet".to_string()))?;
6767

actors/evm/src/interpreter/instructions/lifecycle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::interpreter::address::Address;
1+
use crate::interpreter::address::EthAddress;
22
use {
33
crate::interpreter::{ExecutionState, StatusCode, System},
44
fil_actors_runtime::runtime::Runtime,
@@ -19,7 +19,7 @@ pub fn selfdestruct<'r, BS: Blockstore, RT: Runtime<BS>>(
1919
state: &mut ExecutionState,
2020
_system: &'r mut System<'r, BS, RT>,
2121
) -> Result<(), StatusCode> {
22-
let beneficiary_addr = Address::try_from(state.stack.pop())?;
22+
let beneficiary_addr = EthAddress::try_from(state.stack.pop())?;
2323
let id_addr = beneficiary_addr.as_id_address().expect("no support for non-ID addresses yet");
2424
state.selfdestroyed = Some(id_addr);
2525
Ok(())

actors/evm/tests/call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod asm;
22

3-
use evm::interpreter::address::Address as EVMAddress;
3+
use evm::interpreter::address::EthAddress;
44
use evm::interpreter::U256;
55
use fil_actor_evm as evm;
66
use fil_actors_runtime::test_utils::*;
@@ -77,7 +77,7 @@ fn test_call() {
7777
let target = FILAddress::new_id(0x100);
7878
rt.actor_code_cids.insert(target, *EVM_ACTOR_CODE_ID);
7979

80-
let evm_target = EVMAddress::from_id_address(&target).unwrap();
80+
let evm_target = EthAddress::from_id_address(&target).unwrap();
8181
let evm_target_word = evm_target.as_evm_word();
8282

8383
// dest + method 0 with no data
@@ -216,7 +216,7 @@ fn test_callactor() {
216216
let target = FILAddress::new_id(0x100);
217217
rt.actor_code_cids.insert(target, *EVM_ACTOR_CODE_ID);
218218

219-
let evm_target = EVMAddress::from_id_address(&target).unwrap();
219+
let evm_target = EthAddress::from_id_address(&target).unwrap();
220220
let evm_target_word = evm_target.as_evm_word();
221221

222222
// dest + method 0x42 with no data

0 commit comments

Comments
 (0)