Refactor TransactionErr and TPU events to make them more structured and distinctive
Problem:
Currently the main variant to convey transaction errors is TransactionErr::Plain(String). In some cases, when error needs a user reaction, passing errors in String is not convenient for the GUI to process it.
-
For e.g. in case of insufficient funds in a withdraw or simply send_raw_transaction call to Eth network we return this error as a string
code: ServerError(-32000), message: \"insufficient funds for gas * price + value: balance ... , tx cost ..., overshot .... A multilingual GUI can't just display such an error so it would need to parse it by itself to react (this is what komodo-wallet actually does). In case of Ethereum the network does not return a specific code for errors like 'insufficient funds' and I believe this is a task for the API to process them and return as structured errors (for e.g. etherjs code does this). -
Another case is swap events reflecting failures during the swap. They contain enums like AbortReason, MakerPaymentRefundReason, TakerPaymentRefundReason. Again such objects have attached TransactionErr, ValidatePaymentError errors simply converted to a String. This makes it harder for GUI to show what wrong happened during the swap. Better to make those String descriptions as structured error with error_type and optional params. For example:
{ "error_type": InsufficientFunds", "available": 1000, "required": 1200 }. -
It's probably not necessary to refactor errors in legacy swap events as we target TPU.
Solution
- Parse blockchain errors messages requiring user action (like insufficient funds) and add them as TransactionErr variants as structs (with additional properties if needed for some error type).
- In AbortReason, MakerPaymentRefundReason, TakerPaymentRefundReason variants replace the simple String description on structured errors.