Skip to content

Commit

Permalink
review: remove "address" param from addr_to_string func and use self.…
Browse files Browse the repository at this point in the history
…my_addr() directly inside it
  • Loading branch information
laruh committed Dec 29, 2024
1 parent 869019b commit 0f31d07
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6980,7 +6980,7 @@ impl ParseCoinAssocTypes for EthCoin {
}
}

fn addr_to_string(&self, address: &Self::Address) -> String { eth_addr_to_hex(address) }
async fn my_addr_as_string(&self) -> String { eth_addr_to_hex(&self.my_addr().await) }

fn parse_address(&self, address: &str) -> Result<Self::Address, Self::AddressParseError> {
// crate `Address::from_str` supports both address variants with and without `0x` prefix
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,13 +1550,13 @@ pub trait ParseCoinAssocTypes {

async fn my_addr(&self) -> Self::Address;

/// Converts coin `Self::Address` type into a properly formatted string representation.
/// Should convert coin `Self::Address` type into a properly formatted string representation.
///
/// Don't use `to_string` directly on `Self::Address` types in generic TPU code!
/// It may produce abbreviated or non-standard formats (e.g. `ethereum_types::Address` will be like this `0x7cc9…3874`),
/// which are not guaranteed to be parsable back into the original `Address` type.
/// This function should ensure the resulting string is consistently formatted and fully reversible.
fn addr_to_string(&self, address: &Self::Address) -> String;
async fn my_addr_as_string(&self) -> String;

fn parse_address(&self, address: &str) -> Result<Self::Address, Self::AddressParseError>;

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl ParseCoinAssocTypes for TestCoin {

async fn my_addr(&self) -> Self::Address { todo!() }

fn addr_to_string(&self, address: &Self::Address) -> String { unimplemented!() }
async fn my_addr_as_string(&self) -> String { unimplemented!() }

fn parse_address(&self, address: &str) -> Result<Self::Address, Self::AddressParseError> { todo!() }

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl<T: UtxoCommonOps> ParseCoinAssocTypes for T {
}
}

fn addr_to_string(&self, address: &Self::Address) -> String { address.to_string() }
async fn my_addr_as_string(&self) -> String { self.my_addr().await.to_string() }

fn parse_address(&self, address: &str) -> Result<Self::Address, Self::AddressParseError> {
self.address_from_str(address)
Expand Down
3 changes: 1 addition & 2 deletions mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@ impl<MakerCoin: MmCoin + MakerCoinSwapOpsV2, TakerCoin: MmCoin + TakerCoinSwapOp

async fn on_changed(self: Box<Self>, state_machine: &mut Self::StateMachine) -> StateResult<Self::StateMachine> {
let unique_data = state_machine.unique_data();
let taker_coin_address = state_machine.taker_coin.my_addr().await;

let maker_negotiation_msg = MakerNegotiation {
started_at: state_machine.started_at,
Expand All @@ -924,7 +923,7 @@ impl<MakerCoin: MmCoin + MakerCoinSwapOpsV2, TakerCoin: MmCoin + TakerCoinSwapOp
taker_coin_htlc_pub: state_machine.taker_coin.derive_htlc_pubkey_v2_bytes(&unique_data),
maker_coin_swap_contract: state_machine.maker_coin.swap_contract_address().map(|bytes| bytes.0),
taker_coin_swap_contract: state_machine.taker_coin.swap_contract_address().map(|bytes| bytes.0),
taker_coin_address: state_machine.taker_coin.addr_to_string(&taker_coin_address),
taker_coin_address: state_machine.taker_coin.my_addr_as_string().await,
};
debug!("Sending maker negotiation message {:?}", maker_negotiation_msg);
let swap_msg = SwapMessage {
Expand Down

0 comments on commit 0f31d07

Please sign in to comment.