Skip to content

Add proper status / error codes to the Wallet API #10343

@rbrunner7

Description

@rbrunner7

With Wallet API I mean wallet2_api.h and the implementation behind it, an API that lets you implement wallet apps that is on a higher level of abstraction than wallet2.h. The Monero GUI wallet app uses this, as an example.

There is a WIP PR to significantly expand the Wallet API here, with a goal of making it a full / feature complete replacement for using wallet2 directly. That expanded API is used in another PR here to refactor the code of the Monero CLI wallet app to completely stop using wallet2 directly and using the Wallet API exclusively. That work is quite far along already.

Long-term goal is to stop using wallet2 in any Monero wallet app, making the way free to re-implement the wallet code from the ground up and get rid of the "spaghetti code" in wallet2.cpp. Who knows, maybe we will even be able to use Rust wallet code that became ready and battle-tested in the meantime and spare that implementation work.

Work is currently underway to make the same migration for the Monero RPC wallet server, and it's here where a significant problem surfaced:

The RPC interface is designed to give back detailed error codes, to allow clients to react in sensible ways to problems that occur. You find a list of the codes here: wallet/wallet_rpc_server_error_codes.h

Unfortunately this collides with the current design of the Wallet API which beside textual error info only gives back these status values as result of the last call:

enum Status {
    Status_Ok,
    Status_Error,
    Status_Critical
};

I think it's important for a Wallet RPC server based on the Wallet API to continue giving detailed error codes, like it does now. That in turn would mean to modify the Wallet API code somehow to provide enough info to callers to allow that in a clean way; hacks like parsing the returned error texts to deduct error codes from them do not look promising at all to me.

After checking the current Wallet API code I think that implementing proper error codes would need some work, but be quite doable, because it's not a complex job, just some "grunt work".

I have a proposal how to implement this in a way that does not break the current API. The basic idea: There would be an extended Status enum along these lines:

enum Status {
    Status_Ok,
    Status_Error,
    Status_Critical,

    Status_Wrong_Address,
    Status_Daemon_Is_Busy,
    Status_Not_Enough_Money,
    Status_Watch_Only,
    Status_Tx_Too_Large,
    ....
};

The Wallet API would get a returned status value mode, with two values simple values and detailed values, and a call to switch between the two. Default is simple values, where only Ok, Error and Critical are returned, like now. The RPC wallet server would set the mode to detailed values and generate its error codes based on the returned "extended" codes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions