atomicDEX-API icon indicating copy to clipboard operation
atomicDEX-API copied to clipboard

refactor: replace CoinProtocol with a true error type

Open dimxy opened this issue 10 months ago • 0 comments

Problem

We currently use CoinProtocol type as a error type:

fn try_from_coin_protocol(proto: CoinProtocol) -> Result<Self, MmError<CoinProtocol>>

while this looks like a misconception, we also lose the error reason because of that, for e.g.:

let token_addr = valid_addr_from_str(&contract_address).map_err(|_| CoinProtocol::ERC20 {
                    // TODO: maybe add error description to this err (we're losing 'Invalid address checksum' here)
                    platform: platform.clone(),
                    contract_address,
                })?;

Solution

Let's create a true error type instead of using CoinProtocol and make it propagate lower errors (like Invalid address checksum.

dimxy avatar Feb 27 '25 09:02 dimxy