Skip to content

Prefix removal is unintuitive #470

@drebelsky

Description

@drebelsky

SEP-51 says

Discriminated Union
... In both cases the discriminant name is modified to be snake_case, and truncated removing any shared prefix if there are multiple identifiers in the enum defined as the discriminant. ...
...
Enum
... The string is the name-identifier modified to be snake_case, and truncated removing any shared prefix if there are multiple identifiers in the enum. ...

In practice, it seems like this repo truncates shared prefix based on _-delineations. For example,

enum TransactionResultCode
{
    txFEE_BUMP_INNER_SUCCESS = 1, // fee bump inner transaction succeeded
    txSUCCESS = 0,                // all operations succeeded

    txFAILED = -1, // one of the operations failed (none were applied)

    txTOO_EARLY = -2,         // ledger closeTime before minTime
    txTOO_LATE = -3,          // ledger closeTime after maxTime
    txMISSING_OPERATION = -4, // no operation was specified
    txBAD_SEQ = -5,           // sequence number does not match source account

    txBAD_AUTH = -6,             // too few valid signatures / wrong network
    txINSUFFICIENT_BALANCE = -7, // fee would bring account below reserve
    txNO_ACCOUNT = -8,           // source account not found
    txINSUFFICIENT_FEE = -9,     // fee is too small
    txBAD_AUTH_EXTRA = -10,      // unused signatures attached to transaction
    txINTERNAL_ERROR = -11,      // an unknown error occurred

    txNOT_SUPPORTED = -12,          // transaction type not supported
    txFEE_BUMP_INNER_FAILED = -13,  // fee bump inner transaction failed
    txBAD_SPONSORSHIP = -14,        // sponsorship not confirmed
    txBAD_MIN_SEQ_AGE_OR_GAP = -15, // minSeqAge or minSeqLedgerGap conditions not met
    txMALFORMED = -16,              // precondition is invalid
    txSOROBAN_INVALID = -17         // soroban-specific preconditions were not met
};
$ echo 'AAAAAA==' | stellar xdr decode --type TransactionResultCode
"tx_success"
$ 'AAAAAQ==' | stellar xdr decode --type TransactionResultCode
"tx_fee_bump_inner_success"

Note that each result code is prefixed with tx, but that they are kept after the transformation.

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