Skip to content
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
33 changes: 33 additions & 0 deletions ipc/cli/src/commands/util/eth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: MIT
//! Eth address util

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_api::evm::payload_to_evm_address;
use std::fmt::Debug;
use std::str::FromStr;

use crate::{CommandLineHandler, GlobalArguments};

pub(crate) struct F4ToEthAddr;

#[async_trait]
impl CommandLineHandler for F4ToEthAddr {
type Arguments = F4ToEthAddrArgs;

async fn handle(_global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
let addr = Address::from_str(&arguments.addr)?;
let eth_addr = payload_to_evm_address(addr.payload())?;
log::info!("eth address: {:?}", eth_addr);
Ok(())
}
}

#[derive(Debug, Args)]
#[command(about = "Get Ethereum address for an F4")]
pub(crate) struct F4ToEthAddrArgs {
#[arg(long, help = "F4 address to get the underlying Ethereum addr from")]
pub addr: String,
}
2 changes: 1 addition & 1 deletion ipc/cli/src/commands/util/f4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl CommandLineHandler for EthToF4Addr {

async fn handle(_global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
let eth_addr = EthAddress::from_str(&arguments.addr)?;
log::info!("f4 address: {:}", Address::from(eth_addr));
log::info!("f4 address: {}", Address::from(eth_addr));
Ok(())
}
}
Expand Down
4 changes: 4 additions & 0 deletions ipc/cli/src/commands/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::{CommandLineHandler, GlobalArguments};

use clap::{Args, Subcommand};

use self::eth::{F4ToEthAddr, F4ToEthAddrArgs};
use self::f4::{EthToF4Addr, EthToF4AddrArgs};

mod eth;
mod f4;

#[derive(Debug, Args)]
Expand All @@ -20,11 +22,13 @@ impl UtilCommandsArgs {
pub async fn handle(&self, global: &GlobalArguments) -> anyhow::Result<()> {
match &self.command {
Commands::EthToF4Addr(args) => EthToF4Addr::handle(global, args).await,
Commands::F4ToEthAddr(args) => F4ToEthAddr::handle(global, args).await,
}
}
}

#[derive(Debug, Subcommand)]
pub(crate) enum Commands {
EthToF4Addr(EthToF4AddrArgs),
F4ToEthAddr(F4ToEthAddrArgs),
}