solana-web3.js
solana-web3.js copied to clipboard
Experimental: type errors in `getTransaction`
Overview
We've come across this issue a few times where using the pattern like TSomething extends true ? {extraField: X} : Record<string, never> to conditionally add fields to a response, doesn't work correctly in the experimental RPC. This comes down to https://github.com/solana-labs/solana-web3.js/pull/1531
I noticed we use that pattern in getTransaction and wanted to figure out why it works there. Unfortunately I don't think it does
Steps to reproduce
Replit: https://replit.com/@mcintyre94/tx-transaction-version#index.ts
Code:
const address = 'abc' as Base58EncodedAddress;
const tx1 = await rpc
.getTransaction(address, {encoding: 'json'}) // no maxSupportedTransactionVersion
.send();
tx1?.version; // type checks as TransactionVersion | undefined, should be type error I think?
tx1?.meta!.loadedAddresses // type checks as {writable: [...], readable: [...]} | undefined, should be type error I think?
tx1?.transaction.message.addressTableLookups; // correctly type error
const tx2 = await rpc
.getTransaction(address, {encoding: 'json', maxSupportedTransactionVersion: 0}) // with maxSupportedTransactionVersion
.send();
tx2?.version; // type checks as TransactionVersion | undefined, should be TransactionVersion
tx2?.meta!.loadedAddresses // correctly type checks (can be undefined for legacy tx)
tx2?.transaction.message.addressTableLookups; // missing incorrectly (defined for v0 tx)
Description of bug
-
top-level
versionfield:- should not be set if
maxSupportedTransactionVersionis unset. But is being added asTransactionVersion | undefined - should be set if
maxSupportedTransactionVersionis set, and typed asTransactionVersion. But is being added asTransactionVersion | undefined
- should not be set if
-
meta
loadedAddressesfield:- should not be set if
maxSupportedTransactionVersionis unset. But is being added as{writable: [...], readable: [...]} | undefined - should be set if
maxSupportedTransactionVersionis set, and typed as{writable: [...], readable: [...]} | undefined(it can be undefined if the requested transaction is legacy). This is working correctly
- should not be set if
-
transaction message
addressTableLookupsfield:- should not be set if
maxSupportedTransactionVersionis unset. This is correct - should be set if
maxSupportedTransactionVersionis set, and typed asAddressTableLookup[] | undefined(it can be undefined if the requested transaction is legacy). This is not working correctly, it never seems to be defined
- should not be set if
Crap. I'll fix this.
is this issue/bug still existing? I wish to work on this.
is this issue/bug still existing? I wish to work on this.
Go right ahead! You can use getBlock as reference if you need!
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.