Skip to content

list index out of range in decode_create_instruction #3

@LongShao007

Description

@LongShao007

Error message:

Error decoding instruction: list index out of range

It comes from this code:

def get_account_key(index: int) -> str:
    if index >= len(accounts):
        return "N/A"
    account_index = accounts[index]
    return base58.b58encode(keys[account_index]).decode()

Cause

  • accounts[index] gives account_index.
  • For some instructions, account_index is >= len(keys), so keys[account_index] throws IndexError.

Fix
Make the function check both bounds:

def get_account_key(index: int) -> str:
    if index >= len(accounts):
        return "N/A"
    account_index = accounts[index]
    if account_index >= len(keys):
        return "N/A"
    return base58.b58encode(keys[account_index]).decode()

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