Skip to content

stellar ledger entry fetch trustline --asset rejects valid asset codes that aren't exactly 4 or 12 characters #2395

@leighmcculloch

Description

@leighmcculloch

What problem does your feature solve?

The stellar ledger entry fetch trustline --asset command rejects valid asset codes that aren't exactly 4 or 12 characters long. For example, PYUSD (5 characters) fails:

$ stellar ledger entry fetch trustline --asset PYUSD:GDQE7IXJ4HUHV6RQHIUPRJSEZE4DRS5WY577O2FY6YQ5LVWZ7JZTU2V5 --account GBEPTCX3INOO7565JDEFNCGMKQVTUIWDB356BASWME74RDJOCGQEI7WP
error: provided asset is invalid: PYUSD:GDQE7IXJ4HUHV6RQHIUPRJSEZE4DRS5WY577O2FY6YQ5LVWZ7JZTU2V5

The code matches on the exact length of the asset code string, only accepting lengths 4 and 12:

match code.len() {
4 => TrustLineAsset::CreditAlphanum4(AlphaNum4 {
asset_code: AssetCode4(code.as_bytes().try_into()?),
issuer,
}),
12 => TrustLineAsset::CreditAlphanum12(AlphaNum12 {
asset_code: AssetCode12(code.as_bytes().try_into()?),
issuer,
}),

Stellar asset codes are 1-4 characters (AssetCode4) or 5-12 characters (AssetCode12), right-padded with zero bytes to fill the fixed-size array.

What would you like to see?

Accept asset codes of any length from 1-12 characters, mapping 1-4 character codes to CreditAlphanum4 and 5-12 character codes to CreditAlphanum12, with the code right-padded with 0 bytes to fill the fixed-size array.

What alternatives are there?

Require users to manually pad their asset codes to 4 or 12 characters, which is not ergonomic and differs from how assets are represented elsewhere in the Stellar ecosystem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions