Skip to content

Add IsTokenMint helper#396

Open
cloakd wants to merge 1 commit intosolana-foundation:mainfrom
cloakd:is_token_mint
Open

Add IsTokenMint helper#396
cloakd wants to merge 1 commit intosolana-foundation:mainfrom
cloakd:is_token_mint

Conversation

@cloakd
Copy link
Copy Markdown
Contributor

@cloakd cloakd commented Apr 15, 2026

When working with Token2022 determining token mint is a bit annoying

Helper takes raw account and checks the data len + byte to check if its a mint correctly

We could add this as its own helper in token_2022 but thought it sat better pre-decode

@sonicfromnewyoke
Copy link
Copy Markdown
Contributor

sonicfromnewyoke commented Apr 15, 2026

many thanks for the contribution, but i'd like to use the same (or similar approach) to what agave does in the account decoder: agave doesn't use magic byte offsets at all. Instead, it tries to deserialize the data as each type and lets the unpack logic decide

after merging of #385 i'll be unblocked to make something similar to what StateWithExtensions::unpack() internally does:

  1. validates data length against the base struct size
  2. checks the AccountType discriminator byte at the correct offset for that specific type
  3. parses TLV extensions if present

MR above already have ParseMintWithExtensions and ParseAccountWithExtensions

so the resulting code will be somehow similar to the following:

func IsTokenMint(acc *Account) bool {
    if acc == nil {
        return false
    }
    data := acc.Data.GetBinary()
    
    switch acc.Owner {
    case solana.TokenProgramID:
        return len(data) == MintSize // 82
    case solana.Token2022ProgramID:
        _, err := ParseMintWithExtensions(data)
        return err == nil
    }
    return false
}

but to be honest, i don't sure this IsTokenMint is actually needed (just a bool flag), because is more likely you would like to decode the account into Mint struct (in this example) and opperate with it as with decoded one

glad to hear your oppinion on it and actual use-case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants