Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Type Definition for TransactionJsonParsed #80

Closed
mdfr11 opened this issue Jan 28, 2025 · 1 comment · Fixed by #85
Closed

Incorrect Type Definition for TransactionJsonParsed #80

mdfr11 opened this issue Jan 28, 2025 · 1 comment · Fixed by #85
Assignees
Labels
bug Something isn't working

Comments

@mdfr11
Copy link

mdfr11 commented Jan 28, 2025

Overview

I found a bug in the type definition of TransactionJsonParsed. The accountKeys field is typed as a fixed-length tuple instead of an array, causing a TypeScript error when accessing or defining multiple keys.

Steps to reproduce

  1. Use the following code:
import { createSolanaRpc, signature } from '@solana/web3.js';

const rpcConnection = createSolanaRpc('https://api.mainnet-beta.solana.com');

async function getTransaction() {
  const transaction = await rpcConnection
    .getTransaction(
      signature(
        'EnU3TPTWnXxmPDjE6GAq8qwc1h734jMkkHKCu72VNQgLLLVhiDsugK2Cw66h39YLxrdcFzVctL6DB962vjirMJX',
      ),
      {
        commitment: 'confirmed',
        maxSupportedTransactionVersion: 0,
        encoding: 'jsonParsed',
      },
    )
    .send();

  return transaction;
}

getTransaction().then((res) => {
  const accKey = res?.transaction.message.accountKeys[1];

  console.log(accKey);
});

  1. Observe this TypeScript error:
Tuple type '[{ pubkey: Address; signer: boolean; source: string; writable: boolean; }]' of length '1' has no element at index '1'.

Description of bug

The accountKeys field is typed as:

accountKeys: [
    {
        pubkey: Address;
        signer: boolean;
        source: string;
        writable: boolean;
    },
];

This limits accountKeys to a single element and throws an error when accessing indexes beyond [0]. However, accountKeys should support multiple objects.

Suggested Fix

Change the type to:

accountKeys: Array<{
    pubkey: Address;
    signer: boolean;
    source: string;
    writable: boolean;
}>;
@mdfr11 mdfr11 added the bug Something isn't working label Jan 28, 2025
@steveluscher
Copy link
Collaborator

Nice.

@mcintyre94, want to kill this one off?

Related: source in that data structure appears to be source?: 'transaction' | 'lookup_table' rather than source: string.

https://github.com/anza-xyz/agave/blob/8889b4ac1ea39121dffcbc95421dbffae737c1fe/transaction-status-client-types/src/lib.rs#L134-L148

steveluscher pushed a commit that referenced this issue Jan 31, 2025
#### Problem

`accountKeys` was incorrectly typed as a list containing one account key, instead of a list of arbitrary length of account keys

#### Summary of Changes

- Fix the type
- Change the type of `source` to the enum it comes from (https://github.com/anza-xyz/agave/blob/8889b4ac1ea39121dffcbc95421dbffae737c1fe/transaction-status-client-types/src/lib.rs#L134-L148)

Fixes #80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants