diff --git a/mm2src/coins/eth.rs b/mm2src/coins/eth.rs index 6502275d12..4e11ff429c 100644 --- a/mm2src/coins/eth.rs +++ b/mm2src/coins/eth.rs @@ -6999,10 +6999,10 @@ impl ToBytes for SignedEthTx { #[derive(Debug, Display, EnumFromStringify)] pub enum EthAssocTypesError { - InvalidHexString(String), #[from_stringify("DecoderError")] TxParseError(String), ParseSignatureError(String), + ParseAddressError(String), } #[derive(Debug, Display)] @@ -7041,8 +7041,10 @@ impl ParseCoinAssocTypes for EthCoin { } } + fn addr_to_string(&self, address: &Self::Address) -> String { eth_addr_to_hex(address) } + fn parse_address(&self, address: &str) -> Result { - Address::from_str(address).map_to_mm(|e| EthAssocTypesError::InvalidHexString(e.to_string())) + addr_from_str(address).map_to_mm(EthAssocTypesError::ParseAddressError) } /// As derive_htlc_pubkey_v2 returns coin specific pubkey we can use [Public::from_slice] directly diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index 06f9c8c52e..4e5e7fd5ad 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -1547,6 +1547,14 @@ pub trait ParseCoinAssocTypes { async fn my_addr(&self) -> Self::Address; + /// Converts the coin `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 ensures the resulting string is consistently formatted and fully reversible. + fn addr_to_string(&self, address: &Self::Address) -> String; + fn parse_address(&self, address: &str) -> Result; fn parse_pubkey(&self, pubkey: &[u8]) -> Result; diff --git a/mm2src/coins/test_coin.rs b/mm2src/coins/test_coin.rs index d3068b812a..fcb4233765 100644 --- a/mm2src/coins/test_coin.rs +++ b/mm2src/coins/test_coin.rs @@ -456,6 +456,8 @@ impl ParseCoinAssocTypes for TestCoin { async fn my_addr(&self) -> Self::Address { todo!() } + fn addr_to_string(&self, address: &Self::Address) -> String { unimplemented!() } + fn parse_address(&self, address: &str) -> Result { todo!() } fn parse_pubkey(&self, pubkey: &[u8]) -> Result { unimplemented!() } diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index 6d98451c7f..f1c055f3fc 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -1053,6 +1053,8 @@ impl ParseCoinAssocTypes for T { } } + fn addr_to_string(&self, address: &Self::Address) -> String { address.to_string() } + fn parse_address(&self, address: &str) -> Result { self.address_from_str(address) } diff --git a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs index 3b0b20cc7b..a306ab97e9 100644 --- a/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs +++ b/mm2src/mm2_main/src/lp_swap/maker_swap_v2.rs @@ -913,6 +913,7 @@ impl, state_machine: &mut Self::StateMachine) -> StateResult { 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, @@ -922,7 +923,7 @@ impl